Skip to content

Commit

Permalink
queue-runner: track jobsets by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed Jan 15, 2022
1 parent f487959 commit 8bbd17d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/hydra-queue-runner/queue-monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ bool State::getQueuedBuilds(Connection & conn,
pqxx::work txn(conn);

auto res = txn.exec_params
("select id, project, jobset, job, drvPath, maxsilent, timeout, timestamp, globalPriority, priority from Builds "
"where id > $1 and finished = 0 order by globalPriority desc, id",
("select builds.id, builds.jobset_id, jobsets.project as project, "
"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);

for (auto const & row : res) {
Expand All @@ -110,6 +113,7 @@ bool State::getQueuedBuilds(Connection & conn,
auto build = std::make_shared<Build>(
localStore->parseStorePath(row["drvPath"].as<string>()));
build->id = id;
build->jobsetId = row["jobset_id"].as<int>();
build->projectName = row["project"].as<string>();
build->jobsetName = row["jobset"].as<string>();
build->jobName = row["job"].as<string>();
Expand All @@ -118,7 +122,7 @@ bool State::getQueuedBuilds(Connection & conn,
build->timestamp = row["timestamp"].as<time_t>();
build->globalPriority = row["globalPriority"].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);
newBuildsByID[id] = build;
Expand Down Expand Up @@ -569,7 +573,7 @@ Step::ptr State::createStep(ref<Store> destStore,


Jobset::ptr State::createJobset(pqxx::work & txn,
const std::string & projectName, const std::string & jobsetName)
const std::string & projectName, const std::string & jobsetName, const int & jobsetID)
{
auto p = std::make_pair(projectName, jobsetName);

Expand All @@ -580,9 +584,8 @@ Jobset::ptr State::createJobset(pqxx::work & txn,
}

auto res = txn.exec_params1
("select schedulingShares from Jobsets where project = $1 and name = $2",
projectName,
jobsetName);
("select schedulingShares from Jobsets where id = $1",
jobsetID);
if (res.empty()) throw Error("missing jobset - can't happen");

auto shares = res["schedulingShares"].as<unsigned int>();
Expand All @@ -593,10 +596,9 @@ Jobset::ptr State::createJobset(pqxx::work & txn,
/* Load the build steps from the last 24 hours. */
auto res2 = txn.exec_params
("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,
projectName,
jobsetName);
jobsetID);
for (auto const & row : res2) {
time_t startTime = row["startTime"].as<time_t>();
time_t stopTime = row["stopTime"].as<time_t>();
Expand Down
3 changes: 2 additions & 1 deletion src/hydra-queue-runner/state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct Build
BuildID id;
nix::StorePath drvPath;
std::map<std::string, nix::StorePath> outputs;
int jobsetId;
std::string projectName, jobsetName, jobName;
time_t timestamp;
unsigned int maxSilentTime, buildTimeout;
Expand Down Expand Up @@ -489,7 +490,7 @@ private:
bool & stepFinished);

Jobset::ptr createJobset(pqxx::work & txn,
const std::string & projectName, const std::string & jobsetName);
const std::string & projectName, const std::string & jobsetName, const int & jobsetID);

void processJobsetSharesChange(Connection & conn);

Expand Down

0 comments on commit 8bbd17d

Please sign in to comment.