aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-10-13 15:40:10 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-10-13 15:40:10 +0200
commit644f4fac6a06f269e342bac43966f3d400715ef6 (patch)
tree2385c02c781fd71dfcdc8d18c41a8766a955eec5
parent4622147b57a320a44e6d1336c15d0e333964b9da (diff)
Factor out and generalize worker result uploading
-rw-r--r--bbot/types.hxx1
-rw-r--r--bbot/worker/worker.cxx88
2 files changed, 52 insertions, 37 deletions
diff --git a/bbot/types.hxx b/bbot/types.hxx
index 35f8a69..7e485f7 100644
--- a/bbot/types.hxx
+++ b/bbot/types.hxx
@@ -61,6 +61,7 @@ namespace bbot
using std::invalid_argument;
using std::runtime_error;
using std::system_error;
+ using std::generic_category;
using io_error = std::ios_base::failure;
// <libbutl/optional.mxx>
diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx
index a12a266..2ad8947 100644
--- a/bbot/worker/worker.cxx
+++ b/bbot/worker/worker.cxx
@@ -344,6 +344,53 @@ run_b (tracer& t,
verbosity, buildspec, forward<A> (a)...);
}
+// Upload manifest to the specified TFTP URL with curl. Issue diagnostics and
+// throw failed on invalid manifest or process management errors and throw
+// io_error for input/output errors or non-zero curl exit.
+//
+template <typename T>
+static void
+upload_manifest (tracer& trace,
+ const string& url,
+ const T& m,
+ const char* what)
+{
+ try
+ {
+ tftp_curl c (trace,
+ path ("-"),
+ nullfd,
+ curl::put,
+ url,
+ "--tftp-blksize", tftp_blksize,
+ "--max-time", tftp_put_timeout);
+
+ manifest_serializer s (c.out, url);
+ m.serialize (s);
+
+ c.out.close ();
+ if (!c.wait ())
+ throw_generic_ios_failure (EIO, "non-zero curl exit code");
+ }
+ catch (const manifest_serialization& e)
+ {
+ fail << "invalid " << what << " manifest: " << e.description;
+ }
+ catch (const process_error& e)
+ {
+ fail << "unable to execute curl: " << e;
+ }
+ catch (const system_error& e)
+ {
+ const auto& c (e.code ());
+
+ if (c.category () == generic_category ())
+ throw_generic_ios_failure (c.value (), e.what ());
+ else
+ throw_system_ios_failure (c.value (), e.what ());
+ }
+}
+
static int bbot::
build (size_t argc, const char* argv[])
{
@@ -1613,35 +1660,14 @@ build (size_t argc, const char* argv[])
try
{
- tftp_curl c (trace,
- path ("-"),
- nullfd,
- curl::put,
- url,
- "--tftp-blksize", tftp_blksize,
- "--max-time", tftp_put_timeout);
-
- manifest_serializer s (c.out, url);
- rm.serialize (s);
-
- c.out.close ();
- if (!c.wait ())
- throw_generic_error (EIO);
+ upload_manifest (trace, url, rm, "result");
// We use exit code 2 to signal abnormal termination but where we managed
// to upload the result manifest. See startup() for details.
//
return rm.status != result_status::abnormal ? 0 : 2;
}
- catch (const manifest_serialization& e)
- {
- fail << "invalid result manifest: " << e.description;
- }
- catch (const io_error& e) // In case not derived from system_error.
- {
- error << "unable to upload result manifest to " << url << ": " << e;
- }
- catch (const system_error& e)
+ catch (const io_error& e)
{
error << "unable to upload result manifest to " << url << ": " << e;
}
@@ -1815,21 +1841,9 @@ startup ()
try
{
- tftp_curl c (trace,
- path ("-"),
- nullfd,
- curl::put,
- url,
- "--tftp-blksize", tftp_blksize,
- "--max-time", tftp_put_timeout);
-
- serialize_manifest (rm, c.out, url, "result");
- c.out.close ();
-
- if (!c.wait ())
- throw_generic_error (EIO);
+ upload_manifest (trace, url, rm, "result");
}
- catch (const system_error& e)
+ catch (const io_error& e)
{
fail << "unable to upload result manifest to " << url << ": " << e;
}