diff options
Diffstat (limited to 'mod/ci-common.cxx')
-rw-r--r-- | mod/ci-common.cxx | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/mod/ci-common.cxx b/mod/ci-common.cxx index 6ce47f2..c0ef89f 100644 --- a/mod/ci-common.cxx +++ b/mod/ci-common.cxx @@ -685,12 +685,13 @@ namespace brep return r; } - void ci_start:: - abandon (const basic_mark& error, - const basic_mark&, - const basic_mark* trace, - odb::core::database& db, - tenant_service&& service) const + optional<tenant_service> ci_start:: + cancel (const basic_mark&, + const basic_mark&, + const basic_mark* trace, + odb::core::database& db, + const string& type, + const string& id) const { using namespace odb::core; @@ -701,27 +702,44 @@ namespace brep using query = query<build_tenant>; shared_ptr<build_tenant> t ( - db.query_one<build_tenant> (query::service.id == service.id && - query::service.type == service.type)); - + db.query_one<build_tenant> (query::service.id == id && + query::service.type == type)); if (t == nullptr) - { - error << "unable to find tenant for service " << service.id << ' ' - << service.type; + return nullopt; - return; - } - else if (!t->unloaded_timestamp) - { - error << "tenant " << t->id << " for service " << service.id << ' ' - << service.type << " is already loaded"; + optional<tenant_service> r (move (t->service)); + t->service = nullopt; + t->archived = true; + db.update (t); - return; - } + tr.commit (); + + if (trace != nullptr) + *trace << "CI request " << t->id << " for service " << id << ' ' << type + << " is canceled"; + + return r; + } + + bool ci_start:: + cancel (const basic_mark&, + const basic_mark&, + const basic_mark* trace, + const string& reason, + odb::core::database& db, + const string& tid) const + { + using namespace odb::core; + + assert (!transaction::has_current ()); + + transaction tr (db.begin ()); + + shared_ptr<build_tenant> t (db.find<build_tenant> (tid)); + + if (t == nullptr) + return false; - // We could probably remove the tenant from the database, but let's just - // archive it and keep for troubleshooting. - // if (!t->archived) { t->archived = true; @@ -731,7 +749,11 @@ namespace brep tr.commit (); if (trace != nullptr) - *trace << "unloaded CI request " << t->id << " for service " - << service.id << ' ' << service.type << " is abandoned"; + *trace << "CI request " << tid << " is canceled: " + << (reason.size () < 50 + ? reason + : string (reason, 0, 50) + "..."); + + return true; } } |