From 35359f038f571dc46de3d14af72a2bc911fb0a24 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 18 Mar 2020 22:17:49 +0300 Subject: Implement brep-monitor --- libbrep/build-package.hxx | 2 ++ libbrep/build.cxx | 21 ++++++++++++ libbrep/build.hxx | 82 ++++++++++++++++++++++++++++++++++++++++++++--- libbrep/build.xml | 40 +++++++++++++++++++++++ libbrep/common.hxx | 30 +++++++++++++++++ 5 files changed, 171 insertions(+), 4 deletions(-) (limited to 'libbrep') diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx index 22a8151..702f937 100644 --- a/libbrep/build-package.hxx +++ b/libbrep/build-package.hxx @@ -118,6 +118,8 @@ namespace brep package_id id; upstream_version version; + bool archived; // True if the tenant the package belongs to is archived. + // Database mapping. // #pragma db member(version) set(this.version.init (this.id.version, (?))) diff --git a/libbrep/build.cxx b/libbrep/build.cxx index b6a07c7..db5bda2 100644 --- a/libbrep/build.cxx +++ b/libbrep/build.cxx @@ -80,4 +80,25 @@ namespace brep target (move (trg)) { } + + // build_delay + // + build_delay:: + build_delay (string tnt, + package_name_type pnm, version pvr, + string cfg, + string tnm, version tvr, + timestamp ptm) + : id (package_id (move (tnt), move (pnm), pvr), + move (cfg), + move (tnm), tvr), + tenant (id.package.tenant), + package_name (id.package.name), + package_version (move (pvr)), + configuration (id.configuration), + toolchain_name (id.toolchain_name), + toolchain_version (move (tvr)), + package_timestamp (ptm) + { + } } diff --git a/libbrep/build.hxx b/libbrep/build.hxx index 7e548a4..83b30a8 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -25,7 +25,7 @@ // #define LIBBREP_BUILD_SCHEMA_VERSION_BASE 9 -#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 9, closed) +#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 10, closed) // We have to keep these mappings at the global scope instead of inside // the brep namespace because they need to be also effective in the @@ -212,6 +212,16 @@ namespace brep // optional status; + // Time of setting the result status that can be considered as the build + // task completion (currently all the result_status values). Initialized + // with timestamp_nonexistent by default. + // + // Note that in the future we may not consider abort and abnormal as the + // task completion and, for example, proceed with automatic rebuild (the + // flake monitor idea). + // + timestamp_type completion_timestamp; + // May be present only for the building state. // optional agent_fingerprint; @@ -244,6 +254,10 @@ namespace brep // #pragma db member(timestamp) index + // @@ TMP remove when 0.13.0 is released. + // + #pragma db member(completion_timestamp) default(0) + #pragma db member(results) id_column("") value_column("") \ section(results_section) @@ -259,9 +273,7 @@ namespace brep : tenant (id.package.tenant), package_name (id.package.name), configuration (id.configuration), - toolchain_name (id.toolchain_name) - { - } + toolchain_name (id.toolchain_name) {} }; // Note that ADL can't find the equal operator in join conditions, so we use @@ -340,6 +352,68 @@ namespace brep // #pragma db member(result) column("count(" + build::id.package.name + ")") }; + + // Used to track the package build delays since the last build or, if not + // present, since the first opportunity to build the package. + // + #pragma db object pointer(shared_ptr) session + class build_delay + { + public: + using package_name_type = brep::package_name; + + // If toolchain version is empty, then the object represents a minimum + // delay across all versions of the toolchain. + // + build_delay (string tenant, + package_name_type, version, + string configuration, + string toolchain_name, version toolchain_version, + timestamp package_timestamp); + + build_id id; + + string& tenant; // Tracks id.package.tenant. + package_name_type& package_name; // Tracks id.package.name. + upstream_version package_version; // Original of id.package.version. + string& configuration; // Tracks id.configuration. + string& toolchain_name; // Tracks id.toolchain_name. + upstream_version toolchain_version; // Original of id.toolchain_version. + + // Time of the latest delay report. Initialized with timestamp_nonexistent + // by default. + // + timestamp report_timestamp; + + // Time when the package is initially considered as buildable for this + // configuration and toolchain. It is used to track the build delay if the + // build object is absent (the first build task is not yet issued, the + // build is removed by brep-clean, etc). + // + timestamp package_timestamp; + + // Database mapping. + // + #pragma db member(id) id column("") + + #pragma db member(tenant) transient + #pragma db member(package_name) transient + #pragma db member(package_version) \ + set(this.package_version.init (this.id.package.version, (?))) + #pragma db member(configuration) transient + #pragma db member(toolchain_name) transient + #pragma db member(toolchain_version) \ + set(this.toolchain_version.init (this.id.toolchain_version, (?))) + + private: + friend class odb::access; + + build_delay () + : tenant (id.package.tenant), + package_name (id.package.name), + configuration (id.configuration), + toolchain_name (id.toolchain_name) {} + }; } #endif // LIBBREP_BUILD_HXX diff --git a/libbrep/build.xml b/libbrep/build.xml index 3ade7c8..bf8920b 100644 --- a/libbrep/build.xml +++ b/libbrep/build.xml @@ -1,4 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libbrep/common.hxx b/libbrep/common.hxx index 44028df..b7fc2da 100644 --- a/libbrep/common.hxx +++ b/libbrep/common.hxx @@ -8,6 +8,8 @@ #include #include // static_assert +#include + #include #include @@ -510,6 +512,34 @@ namespace brep compare_version_ne (x.version, y.version, true); } + // Allow comparing the query members with the query parameters bound by + // reference to variables of the package id type (in particular in the + // prepared queries). + // + // Note that it is not operator==() since the query template parameter type + // can not be deduced from the function parameter types and needs to be + // specified explicitly. + // + template + inline auto + equal (const ID& x, const package_id& y) + -> decltype (x.tenant == odb::query::_ref (y.tenant) && + x.name == odb::query::_ref (y.name) && + x.version.epoch == odb::query::_ref (y.version.epoch)) + { + using query = odb::query; + + const auto& qv (x.version); + const canonical_version& v (y.version); + + return x.tenant == query::_ref (y.tenant) && + x.name == query::_ref (y.name) && + qv.epoch == query::_ref (v.epoch) && + qv.canonical_upstream == query::_ref (v.canonical_upstream) && + qv.canonical_release == query::_ref (v.canonical_release) && + qv.revision == query::_ref (v.revision); + } + // Repository id comparison operators. // inline bool -- cgit v1.1