From 39a7404e6cddb2053a87f86935cda566c54bd4e6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 22 Mar 2024 18:00:37 +0300 Subject: Add tenant_service_hints --- mod/mod-build-task.cxx | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'mod/mod-build-task.cxx') diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 0892638..7373ffe 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -1006,12 +1006,13 @@ handle (request& rq, response& rs) // Also, if the tenant_service_build_queued callback is registered, then // create, persist, and stash the queued build objects for all the // unbuilt by the current toolchain and not yet queued configurations of - // the package the build task is created for. Note that for the task - // build, we need to make sure that the third-party service receives the - // `queued` notification prior to the `building` notification (see - // mod/tenant-service.hxx for valid transitions). The `queued` - // notification is assumed to be already sent for the build if the - // respective object exists and any of the following is true for it: + // the package the build task is created for and calculate the hints. + // Note that for the task build, we need to make sure that the + // third-party service receives the `queued` notification prior to the + // `building` notification (see mod/tenant-service.hxx for valid + // transitions). The `queued` notification is assumed to be already sent + // for the build if the respective object exists and any of the + // following is true for it: // // - It is in the queued state (initial_state is build_state::queued). // @@ -1025,6 +1026,7 @@ handle (request& rq, response& rs) const tenant_service_build_queued* tsq (nullptr); optional>> tss; vector qbs; + tenant_service_build_queued::build_queued_hints qhs; optional initial_state; bool rebuild_forced_build (false); bool rebuild_interrupted_rebuild (false); @@ -1096,6 +1098,16 @@ handle (request& rq, response& rs) return r; }; + auto queue_hints = [this] (const build_package& p) + { + buildable_package_count tpc ( + build_db_->query_value ( + query::build_tenant::id == p.id.tenant)); + + return tenant_service_build_queued::build_queued_hints { + tpc == 1, p.configs.size () == 1}; + }; + // Collect the auxiliary machines required for testing of the specified // package configuration and the external test packages, if present for // the specified target configuration (task_auxiliary_machines), @@ -1767,6 +1779,8 @@ handle (request& rq, response& rs) (*initial_state != build_state::queued && !rebuild_forced_build)) { + qhs = queue_hints (*p); + t->queued_timestamp = system_clock::now (); build_db_->update (t); } @@ -1990,6 +2004,8 @@ handle (request& rq, response& rs) // if (!qbs.empty () || !rebuild_interrupted_rebuild) { + qhs = queue_hints (*p); + t->queued_timestamp = system_clock::now (); build_db_->update (t); } @@ -2063,6 +2079,7 @@ handle (request& rq, response& rs) if (auto f = tsq->build_queued (ss, qbs, nullopt /* initial_state */, + qhs, log_writer_)) update_tenant_service_state (conn, qbs.back ().tenant, f); } @@ -2079,7 +2096,11 @@ handle (request& rq, response& rs) qbs.push_back (move (b)); restore_build = true; - if (auto f = tsq->build_queued (ss, qbs, initial_state, log_writer_)) + if (auto f = tsq->build_queued (ss, + qbs, + initial_state, + qhs, + log_writer_)) update_tenant_service_state (conn, qbs.back ().tenant, f); } -- cgit v1.1