From f8141fdc98f0c0d679c87111df13784fd8909350 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Sep 2015 15:55:26 +0200 Subject: [PATCH] Set propagatedFrom for cached failed build steps --- src/hydra-queue-runner/queue-monitor.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index c9d21200..c1a60f60 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -169,7 +169,29 @@ void State::getQueuedBuilds(Connection & conn, std::shared_ptr store, printMsg(lvlError, format("marking build %1% as cached failure") % build->id); if (!build->finishedInDB) { pqxx::work txn(conn); - createBuildStep(txn, 0, build, r, "", bssFailed); + + /* Find the previous build step record, first by + derivation path, then by output path. */ + BuildID propagatedFrom = 0; + + auto res = txn.parameterized + ("select max(build) from BuildSteps where drvPath = $1 and startTime != 0 and stopTime != 0 and status = 1") + (r->drvPath).exec(); + if (!res[0][0].is_null()) propagatedFrom = res[0][0].as(); + + if (!propagatedFrom) { + for (auto & output : r->drv.outputs) { + auto res = txn.parameterized + ("select max(s.build) from BuildSteps s join BuildStepOutputs o on s.build = o.build where path = $1 and startTime != 0 and stopTime != 0 and status = 1") + (output.second.path).exec(); + if (!res[0][0].is_null()) { + propagatedFrom = res[0][0].as(); + break; + } + } + } + + createBuildStep(txn, 0, build, r, "", bssCachedFailure, "", propagatedFrom); txn.parameterized ("update Builds set finished = 1, busy = 0, buildStatus = $2, startTime = $3, stopTime = $3, isCachedBuild = 1 where id = $1 and finished = 0") (build->id)