aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-04-24 11:39:14 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-04-24 11:39:14 +0300
commit5f2539b772d068ddc541f3bbcfcb4a3430fa496e (patch)
treeff2db21780260cde8183b65a5801ce0454966c16 /mod
parent9d539574d55ad5c65d15c040ec40764ffb1f601e (diff)
Fix tenant service related logic in build task handler
Diffstat (limited to 'mod')
-rw-r--r--mod/database-module.cxx10
-rw-r--r--mod/database-module.hxx5
-rw-r--r--mod/mod-build-task.cxx30
3 files changed, 35 insertions, 10 deletions
diff --git a/mod/database-module.cxx b/mod/database-module.cxx
index 07babc6..bbb3e59 100644
--- a/mod/database-module.cxx
+++ b/mod/database-module.cxx
@@ -76,7 +76,7 @@ namespace brep
throw;
}
- void database_module::
+ optional<string> database_module::
update_tenant_service_state (
const connection_ptr& conn,
const string& tid,
@@ -88,6 +88,8 @@ namespace brep
//
assert (build_db_ != nullptr);
+ optional<string> r;
+
for (size_t retry (retry_);; )
{
try
@@ -104,6 +106,8 @@ namespace brep
{
s.data = move (*data);
build_db_->update (t);
+
+ r = move (s.data);
}
}
@@ -121,7 +125,11 @@ namespace brep
HANDLER_DIAG;
l1 ([&]{trace << e << "; " << retry + 1 << " tenant service "
<< "state update retries left";});
+
+ r = nullopt; // Prepare for the next iteration.
}
}
+
+ return r;
}
}
diff --git a/mod/database-module.hxx b/mod/database-module.hxx
index 910cb35..298afbf 100644
--- a/mod/database-module.hxx
+++ b/mod/database-module.hxx
@@ -57,7 +57,8 @@ namespace brep
// Update the tenant-associated service state if the specified
// notification callback-returned function (expected to be not NULL)
- // returns the new state data.
+ // returns the new state data. Return the service state data, if updated,
+ // and nullopt otherwise.
//
// Specifically, start the database transaction, query the service state,
// and call the callback-returned function on this state. If this call
@@ -65,7 +66,7 @@ namespace brep
// state with this data and persist the change. Repeat all the above steps
// on the recoverable database failures (deadlocks, etc).
//
- void
+ optional<string>
update_tenant_service_state (
const odb::core::connection_ptr&,
const string& tid,
diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx
index e0aad4b..c4968a7 100644
--- a/mod/mod-build-task.cxx
+++ b/mod/mod-build-task.cxx
@@ -2205,7 +2205,7 @@ handle (request& rq, response& rs)
{
assert (tss); // Wouldn't be here otherwise.
- const tenant_service& ss (tss->first);
+ tenant_service& ss (tss->first);
// If the task build has no initial state (is just created), then
// temporarily move it into the list of the queued builds until the
@@ -2228,7 +2228,11 @@ handle (request& rq, response& rs)
nullopt /* initial_state */,
qhs,
log_writer_))
- update_tenant_service_state (conn, qbs.back ().tenant, f);
+ {
+ if (optional<string> data =
+ update_tenant_service_state (conn, qbs.back ().tenant, f))
+ ss.data = move (data);
+ }
}
// Send the `queued` notification for the task build, unless it is
@@ -2248,7 +2252,11 @@ handle (request& rq, response& rs)
initial_state,
qhs,
log_writer_))
- update_tenant_service_state (conn, qbs.back ().tenant, f);
+ {
+ if (optional<string> data =
+ update_tenant_service_state (conn, qbs.back ().tenant, f))
+ ss.data = move (data);
+ }
}
if (restore_build)
@@ -2264,11 +2272,15 @@ handle (request& rq, response& rs)
{
assert (tss); // Wouldn't be here otherwise.
- const tenant_service& ss (tss->first);
+ tenant_service& ss (tss->first);
const build& b (*tss->second);
if (auto f = tsb->build_building (ss, b, log_writer_))
- update_tenant_service_state (conn, b.tenant, f);
+ {
+ if (optional<string> data =
+ update_tenant_service_state (conn, b.tenant, f))
+ ss.data = move (data);
+ }
}
// If the task manifest is prepared, then check that the number of the
@@ -2377,11 +2389,15 @@ handle (request& rq, response& rs)
{
assert (tss); // Wouldn't be here otherwise.
- const tenant_service& ss (tss->first);
+ tenant_service& ss (tss->first);
const build& b (*tss->second);
if (auto f = tsb->build_built (ss, b, log_writer_))
- update_tenant_service_state (conn, b.tenant, f);
+ {
+ if (optional<string> data =
+ update_tenant_service_state (conn, b.tenant, f))
+ ss.data = move (data);
+ }
}
}