Merge pull request #1117 from DeterminateSystems/project-jobset/queue-runner

queue-runner: track jobsets by ID
This commit is contained in:
Graham Christensen 2022-01-15 15:57:14 -05:00 committed by GitHub
commit 1caff3a250
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View file

@ -96,8 +96,11 @@ bool State::getQueuedBuilds(Connection & conn,
pqxx::work txn(conn); pqxx::work txn(conn);
auto res = txn.exec_params auto res = txn.exec_params
("select id, project, jobset, job, drvPath, maxsilent, timeout, timestamp, globalPriority, priority from Builds " ("select builds.id, builds.jobset_id, jobsets.project as project, "
"where id > $1 and finished = 0 order by globalPriority desc, id", "jobsets.name as jobset, job, drvPath, maxsilent, timeout, timestamp, "
"globalPriority, priority from Builds "
"inner join jobsets on builds.jobset_id = jobsets.id "
"where builds.id > $1 and finished = 0 order by globalPriority desc, builds.id",
lastBuildId); lastBuildId);
for (auto const & row : res) { for (auto const & row : res) {
@ -110,6 +113,7 @@ bool State::getQueuedBuilds(Connection & conn,
auto build = std::make_shared<Build>( auto build = std::make_shared<Build>(
localStore->parseStorePath(row["drvPath"].as<string>())); localStore->parseStorePath(row["drvPath"].as<string>()));
build->id = id; build->id = id;
build->jobsetId = row["jobset_id"].as<JobsetID>();
build->projectName = row["project"].as<string>(); build->projectName = row["project"].as<string>();
build->jobsetName = row["jobset"].as<string>(); build->jobsetName = row["jobset"].as<string>();
build->jobName = row["job"].as<string>(); build->jobName = row["job"].as<string>();
@ -118,7 +122,7 @@ bool State::getQueuedBuilds(Connection & conn,
build->timestamp = row["timestamp"].as<time_t>(); build->timestamp = row["timestamp"].as<time_t>();
build->globalPriority = row["globalPriority"].as<int>(); build->globalPriority = row["globalPriority"].as<int>();
build->localPriority = row["priority"].as<int>(); build->localPriority = row["priority"].as<int>();
build->jobset = createJobset(txn, build->projectName, build->jobsetName); build->jobset = createJobset(txn, build->projectName, build->jobsetName, build->jobsetId);
newIDs.push_back(id); newIDs.push_back(id);
newBuildsByID[id] = build; newBuildsByID[id] = build;
@ -569,7 +573,7 @@ Step::ptr State::createStep(ref<Store> destStore,
Jobset::ptr State::createJobset(pqxx::work & txn, Jobset::ptr State::createJobset(pqxx::work & txn,
const std::string & projectName, const std::string & jobsetName) const std::string & projectName, const std::string & jobsetName, const JobsetID jobsetID)
{ {
auto p = std::make_pair(projectName, jobsetName); auto p = std::make_pair(projectName, jobsetName);
@ -580,9 +584,8 @@ Jobset::ptr State::createJobset(pqxx::work & txn,
} }
auto res = txn.exec_params1 auto res = txn.exec_params1
("select schedulingShares from Jobsets where project = $1 and name = $2", ("select schedulingShares from Jobsets where id = $1",
projectName, jobsetID);
jobsetName);
if (res.empty()) throw Error("missing jobset - can't happen"); if (res.empty()) throw Error("missing jobset - can't happen");
auto shares = res["schedulingShares"].as<unsigned int>(); auto shares = res["schedulingShares"].as<unsigned int>();
@ -593,10 +596,9 @@ Jobset::ptr State::createJobset(pqxx::work & txn,
/* Load the build steps from the last 24 hours. */ /* Load the build steps from the last 24 hours. */
auto res2 = txn.exec_params auto res2 = txn.exec_params
("select s.startTime, s.stopTime from BuildSteps s join Builds b on build = id " ("select s.startTime, s.stopTime from BuildSteps s join Builds b on build = id "
"where s.startTime is not null and s.stopTime > $1 and project = $2 and jobset = $3", "where s.startTime is not null and s.stopTime > $1 and jobset_id = $2",
time(0) - Jobset::schedulingWindow * 10, time(0) - Jobset::schedulingWindow * 10,
projectName, jobsetID);
jobsetName);
for (auto const & row : res2) { for (auto const & row : res2) {
time_t startTime = row["startTime"].as<time_t>(); time_t startTime = row["startTime"].as<time_t>();
time_t stopTime = row["stopTime"].as<time_t>(); time_t stopTime = row["stopTime"].as<time_t>();

View file

@ -19,6 +19,8 @@
typedef unsigned int BuildID; typedef unsigned int BuildID;
typedef unsigned int JobsetID;
typedef std::chrono::time_point<std::chrono::system_clock> system_time; typedef std::chrono::time_point<std::chrono::system_clock> system_time;
typedef std::atomic<unsigned long> counter; typedef std::atomic<unsigned long> counter;
@ -123,6 +125,7 @@ struct Build
BuildID id; BuildID id;
nix::StorePath drvPath; nix::StorePath drvPath;
std::map<std::string, nix::StorePath> outputs; std::map<std::string, nix::StorePath> outputs;
JobsetID jobsetId;
std::string projectName, jobsetName, jobName; std::string projectName, jobsetName, jobName;
time_t timestamp; time_t timestamp;
unsigned int maxSilentTime, buildTimeout; unsigned int maxSilentTime, buildTimeout;
@ -489,7 +492,7 @@ private:
bool & stepFinished); bool & stepFinished);
Jobset::ptr createJobset(pqxx::work & txn, Jobset::ptr createJobset(pqxx::work & txn,
const std::string & projectName, const std::string & jobsetName); const std::string & projectName, const std::string & jobsetName, const JobsetID);
void processJobsetSharesChange(Connection & conn); void processJobsetSharesChange(Connection & conn);