aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-03-30 23:07:26 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-01 13:13:23 +0300
commit2b2f2dc54856b679e8fd42b053f7361241c0f836 (patch)
treecdba437bf14b65d729ed027869c9ad8041dbe4fd /mod
parent8dec2ac658d78d58437d77be08c9f2614c259cc6 (diff)
Invent alternative package rebuild timeout
Diffstat (limited to 'mod')
-rw-r--r--mod/buildfile2
-rw-r--r--mod/mod-build-task.cxx62
-rw-r--r--mod/module.cli34
-rw-r--r--mod/types-parsers.cxx36
-rw-r--r--mod/types-parsers.hxx9
5 files changed, 133 insertions, 10 deletions
diff --git a/mod/buildfile b/mod/buildfile
index ca46bc4..191d966 100644
--- a/mod/buildfile
+++ b/mod/buildfile
@@ -50,7 +50,7 @@ if $cli.configured
cli.options += --std c++11 -I $src_root --include-with-brackets \
--include-prefix mod --guard-prefix MOD --generate-specifier \
--cxx-prologue "#include <mod/types-parsers.hxx>" \
---cli-namespace brep::cli --generate-file-scanner --option-length 38 \
+--cli-namespace brep::cli --generate-file-scanner --option-length 41 \
--generate-modifier --generate-description --option-prefix ""
# Include the generated cli files into the distribution and don't remove
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<std::chrono::nanoseconds> (
+ uint64_t t (chrono::duration_cast<chrono::nanoseconds> (
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<build> ("mod-build-task-build-query", bq));
diff --git a/mod/module.cli b/mod/module.cli
index fa1d2cc..b59158a 100644
--- a/mod/module.cli
+++ b/mod/module.cli
@@ -199,6 +199,40 @@ namespace brep
"Time to wait before considering a package for a normal rebuild. Must
be specified in seconds. Default is 24 hours."
}
+
+ size_t build-alt-rebuild-timeout
+ {
+ "<seconds>",
+ "Alternative package rebuild timeout to use instead of the normal
+ rebuild timeout (see \cb{build-normal-rebuild-timeout} for details)
+ during the time interval specified with the
+ \cb{build-alt-rebuild-start} and \cb{build-alt-rebuild-stop} options.
+ Must be specified in seconds. Default is the time interval length."
+ }
+
+ duration build-alt-rebuild-start
+ {
+ "<hours>:<minutes>",
+ "The start time of the alternative package rebuild timeout (see
+ \cb{build-alt-rebuild-timeout} for details). Must be specified as
+ a time of day in the local timezone. The \cb{build-alt-rebuild-start}
+ and \cb{build-alt-rebuild-stop} options must be either both specified
+ or absent. If unspecified, then no alternative rebuild timeout will
+ be used."
+ }
+
+ duration build-alt-rebuild-stop
+ {
+ "<hours>:<minutes>",
+ "The end time of the alternative package rebuild timeout (see
+ \cb{build-alt-rebuild-timeout} for details). Must be specified as
+ a time of day in the local timezone. If it is less than the
+ \cb{build-alt-rebuild-start} option value, then the time interval
+ extends through midnight. The \cb{build-alt-rebuild-start} and
+ \cb{build-alt-rebuild-stop} options must be either both specified or
+ absent. If unspecified, then no alternative rebuild timeout will be
+ used."
+ }
};
class build_db
diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx
index ceaab29..dc21e97 100644
--- a/mod/types-parsers.cxx
+++ b/mod/types-parsers.cxx
@@ -3,6 +3,8 @@
#include <mod/types-parsers.hxx>
+#include <libbutl/timestamp.mxx> // from_string()
+
#include <mod/module-options.hxx>
using namespace std;
@@ -50,6 +52,40 @@ namespace brep
parse_path (x, s);
}
+ // Parse time of day.
+ //
+ void parser<duration>::
+ parse (duration& x, bool& xs, scanner& s)
+ {
+ xs = true;
+
+ const char* o (s.next ());
+
+ if (!s.more ())
+ throw missing_value (o);
+
+ const char* v (s.next ());
+
+ // To avoid the manual time of day parsing and validation, let's parse
+ // it as the first Epoch day time and convert the result (timestamp) to
+ // the time elapsed since Epoch (duration).
+ //
+ try
+ {
+ string t ("1970-01-01 ");
+ t += v;
+
+ x = butl::from_string (t.c_str (),
+ "%Y-%m-%d %H:%M",
+ false /* local */).time_since_epoch ();
+ return;
+ }
+ catch (const invalid_argument&) {}
+ catch (const system_error&) {}
+
+ throw invalid_value (o, v);
+ }
+
// Parse repository_location.
//
void parser<repository_location>::
diff --git a/mod/types-parsers.hxx b/mod/types-parsers.hxx
index 091c868..6b851eb 100644
--- a/mod/types-parsers.hxx
+++ b/mod/types-parsers.hxx
@@ -39,6 +39,15 @@ namespace brep
parse (dir_path&, bool&, scanner&);
};
+ // Parse time of day specified in the `hh:mm` form.
+ //
+ template <>
+ struct parser<duration>
+ {
+ static void
+ parse (duration&, bool&, scanner&);
+ };
+
template <>
struct parser<bpkg::repository_location>
{