Commit 1d32a9b6 authored by Peter Jankuliak's avatar Peter Jankuliak
Browse files

Move job timeout calculation and sleep to a dedicated function

parent 308f4424
......@@ -1178,13 +1178,16 @@ public:
using Job = AsyncJob<Retval>;
Jobs(asio::executor exec)
: secure_origin(exec)
: exec(exec)
, secure_origin(exec)
, origin(exec)
, proxy(exec)
, injector_or_dcache(exec)
, all({&secure_origin, &origin, &proxy, &injector_or_dcache})
{}
asio::executor exec;
Job secure_origin;
Job origin;
Job proxy;
......@@ -1242,6 +1245,18 @@ public:
auto jobs = running();
return std::distance(jobs.begin(), jobs.end());
}
void sleep_before_job(Type job_type, Cancel& cancel, Yield& yield) {
size_t n = count_running();
auto timeout = n * std::chrono::seconds(3);
if (log_transactions()) {
yield.log("Starting job with timeout ", timeout.count(), "s");
}
async_sleep(exec, n * chrono::seconds(3), cancel, yield);
}
};
bool is_access_enabled(Jobs::Type job_type) const {
......@@ -1302,7 +1317,7 @@ public:
job->start([
&yield,
n = jobs.count_running(),
&jobs,
name_tag,
func = std::move(func),
exec,
......@@ -1310,13 +1325,8 @@ public:
] (Cancel& c, asio::yield_context y_) {
auto y = yield.detach(y_).tag(name_tag);
auto timeout = n * chrono::seconds(3);
if (log_transactions()) {
y.log("Starting job with timeout ", timeout.count(), "s");
}
jobs.sleep_before_job(job_type, c, y);
async_sleep(exec, n * chrono::seconds(3), c, y);
if (c) return or_throw(y_, err::operation_aborted, boost::none);
sys::error_code ec;
func(c, y[ec]);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment