From 2b2f2dc54856b679e8fd42b053f7361241c0f836 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 30 Mar 2020 23:07:26 +0300 Subject: Invent alternative package rebuild timeout --- mod/mod-build-task.cxx | 62 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'mod/mod-build-task.cxx') diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 17bc15e..edddb89 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -59,6 +59,14 @@ init (scanner& s) if (options_->build_config_specified ()) { + // Verify that build-alt-rebuild-{start,stop} are both either specified or + // not. + // + if (options_->build_alt_rebuild_start_specified () != + options_->build_alt_rebuild_stop_specified ()) + fail << "build-alt-rebuild-start and build-alt-rebuild-stop " + << "configuration options must both be either specified or not"; + database_module::init (*options_, options_->build_db_retry ()); // Check that the database 'build' schema matches the current one. It's @@ -254,12 +262,48 @@ handle (request& rq, response& rs) uint64_t forced_result_expiration_ns ( expiration_ns (options_->build_forced_rebuild_timeout ())); - timestamp normal_rebuild_expiration ( - expiration (options_->build_normal_rebuild_timeout ())); - timestamp forced_rebuild_expiration ( expiration (options_->build_forced_rebuild_timeout ())); + timestamp normal_rebuild_expiration; + + if (options_->build_alt_rebuild_start_specified ()) + { + const duration& start (options_->build_alt_rebuild_start ()); + const duration& stop (options_->build_alt_rebuild_stop ()); + + duration dt (daytime (now)); + + // Note that if the stop time is less than the start time then the + // interval extends through the midnight. + // + bool alt_timeout (start <= stop + ? dt >= start && dt < stop + : dt >= start || dt < stop); + + // If we out of the alternative rebuild timeout interval, then fall back + // to using the normal rebuild timeout. + // + if (alt_timeout) + { + if (!options_->build_alt_rebuild_timeout_specified ()) + { + duration interval_len (start <= stop + ? stop - start + : (24h - start) + stop); + + normal_rebuild_expiration = now - interval_len; + } + else + normal_rebuild_expiration = + expiration (options_->build_alt_rebuild_timeout ()); + } + } + + if (normal_rebuild_expiration == timestamp_nonexistent) + normal_rebuild_expiration = + expiration (options_->build_normal_rebuild_timeout ()); + // Return the challenge (nonce) if brep is configured to authenticate bbot // agents. Return nullopt otherwise. // @@ -301,7 +345,7 @@ handle (request& rq, response& rs) if (!os.wait () || nonce.size () != 64) fail << "unable to generate nonce"; - uint64_t t (chrono::duration_cast ( + uint64_t t (chrono::duration_cast ( now.time_since_epoch ()).count ()); sha256 cs (nonce.data (), nonce.size ()); @@ -397,11 +441,11 @@ handle (request& rq, response& rs) canonical_version (toolchain_version), true /* revision */) && - (bld_query::state == "built" || - ((bld_query::force == "forcing" && - bld_query::timestamp > forced_result_expiration_ns) || - (bld_query::force != "forcing" && // Unforced or forced. - bld_query::timestamp > normal_result_expiration_ns)))); + (bld_query::state == "built" || + (bld_query::force == "forcing" && + bld_query::timestamp > forced_result_expiration_ns) || + (bld_query::force != "forcing" && // Unforced or forced. + bld_query::timestamp > normal_result_expiration_ns))); prep_bld_query bld_prep_query ( conn->prepare_query ("mod-build-task-build-query", bq)); -- cgit v1.1