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-27 15:49:45 +0200
commit994665e567e2538f57de9474f498cfa0095a0050 (patch)
tree495e9f7ccd848eb7f634b41a2588f5f7d4b5280f
parent49653c56bd5b9c7b8ad459b278634ddbb9115a74 (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 26fa26b..5415a9a 100644
--- a/bbot/worker/worker.cxx
+++ b/bbot/worker/worker.cxx
@@ -297,6 +297,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[])
{
@@ -1382,35 +1429,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;
}
@@ -1584,21 +1610,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;
}