Unify build and step status codes

Also remove the obsolete status code 5 from the database.
This commit is contained in:
Eelco Dolstra 2016-03-09 15:15:12 +01:00
parent 9127f5bbc3
commit 80ff78b1b6
8 changed files with 36 additions and 53 deletions

View file

@ -116,7 +116,7 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore, Step::ptr step,
{ {
auto mc = startDbUpdate(); auto mc = startDbUpdate();
pqxx::work txn(*conn); pqxx::work txn(*conn);
stepNr = createBuildStep(txn, result.startTime, build, step, machine->sshName, bssBusy); stepNr = createBuildStep(txn, result.startTime, build, step, machine->sshName, bsBusy);
txn.commit(); txn.commit();
} }
@ -171,7 +171,7 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore, Step::ptr step,
auto mc = startDbUpdate(); auto mc = startDbUpdate();
pqxx::work txn(*conn); pqxx::work txn(*conn);
finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, build->id, finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, build->id,
stepNr, machine->sshName, bssAborted, result.errorMsg); stepNr, machine->sshName, bsAborted, result.errorMsg);
txn.commit(); txn.commit();
if (quit) exit(1); if (quit) exit(1);
return sRetry; return sRetry;
@ -222,7 +222,7 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore, Step::ptr step,
pqxx::work txn(*conn); pqxx::work txn(*conn);
finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, finishBuildStep(txn, result.startTime, result.stopTime, result.overhead,
build->id, stepNr, machine->sshName, bssSuccess); build->id, stepNr, machine->sshName, bsSuccess);
for (auto & b : direct) for (auto & b : direct)
markSucceededBuild(txn, b, res, build != b || result.status != BuildResult::Built, markSucceededBuild(txn, b, res, build != b || result.status != BuildResult::Built,
@ -314,11 +314,6 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore, Step::ptr step,
result.status == BuildResult::LogLimitExceeded ? bsLogLimitExceeded : result.status == BuildResult::LogLimitExceeded ? bsLogLimitExceeded :
result.canRetry() ? bsAborted : result.canRetry() ? bsAborted :
bsFailed; bsFailed;
BuildStepStatus buildStepStatus =
result.status == BuildResult::TimedOut ? bssTimedOut :
result.status == BuildResult::LogLimitExceeded ? bssLogLimitExceeded :
result.canRetry() ? bssAborted :
bssFailed;
/* For standard failures, we don't care about the error /* For standard failures, we don't care about the error
message. */ message. */
@ -340,12 +335,12 @@ State::StepResult State::doBuildStep(nix::ref<Store> destStore, Step::ptr step,
build2->finishedInDB) build2->finishedInDB)
continue; continue;
createBuildStep(txn, 0, build2, step, machine->sshName, createBuildStep(txn, 0, build2, step, machine->sshName,
buildStepStatus, result.errorMsg, build == build2 ? 0 : build->id); buildStatus, result.errorMsg, build == build2 ? 0 : build->id);
} }
if (!cachedFailure) if (!cachedFailure)
finishBuildStep(txn, result.startTime, result.stopTime, result.overhead, finishBuildStep(txn, result.startTime, result.stopTime, result.overhead,
build->id, stepNr, machine->sshName, buildStepStatus, result.errorMsg); build->id, stepNr, machine->sshName, buildStatus, result.errorMsg);
/* Mark all builds that depend on this derivation as failed. */ /* Mark all builds that depend on this derivation as failed. */
for (auto & build2 : indirect) { for (auto & build2 : indirect) {

View file

@ -202,7 +202,7 @@ void State::clearBusy(Connection & conn, time_t stopTime)
pqxx::work txn(conn); pqxx::work txn(conn);
txn.parameterized txn.parameterized
("update BuildSteps set busy = 0, status = $1, stopTime = $2 where busy = 1") ("update BuildSteps set busy = 0, status = $1, stopTime = $2 where busy = 1")
((int) bssAborted) ((int) bsAborted)
(stopTime, stopTime != 0).exec(); (stopTime, stopTime != 0).exec();
txn.commit(); txn.commit();
} }
@ -220,7 +220,7 @@ int State::allocBuildStep(pqxx::work & txn, Build::ptr build)
int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step, int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step,
const std::string & machine, BuildStepStatus status, const std::string & errorMsg, BuildID propagatedFrom) const std::string & machine, BuildStatus status, const std::string & errorMsg, BuildID propagatedFrom)
{ {
int stepNr = allocBuildStep(txn, build); int stepNr = allocBuildStep(txn, build);
@ -230,13 +230,13 @@ int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build,
(stepNr) (stepNr)
(0) // == build (0) // == build
(step->drvPath) (step->drvPath)
(status == bssBusy ? 1 : 0) (status == bsBusy ? 1 : 0)
(startTime, startTime != 0) (startTime, startTime != 0)
(step->drv.platform) (step->drv.platform)
((int) status, status != bssBusy) ((int) status, status != bsBusy)
(propagatedFrom, propagatedFrom != 0) (propagatedFrom, propagatedFrom != 0)
(errorMsg, errorMsg != "") (errorMsg, errorMsg != "")
(startTime, startTime != 0 && status != bssBusy) (startTime, startTime != 0 && status != bsBusy)
(machine).exec(); (machine).exec();
for (auto & output : step->drv.outputs) for (auto & output : step->drv.outputs)
@ -249,7 +249,7 @@ int State::createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build,
void State::finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime, unsigned int overhead, void State::finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime, unsigned int overhead,
BuildID buildId, int stepNr, const std::string & machine, BuildStepStatus status, BuildID buildId, int stepNr, const std::string & machine, BuildStatus status,
const std::string & errorMsg, BuildID propagatedFrom) const std::string & errorMsg, BuildID propagatedFrom)
{ {
assert(startTime); assert(startTime);

View file

@ -205,7 +205,7 @@ bool State::getQueuedBuilds(Connection & conn, ref<Store> localStore,
} }
} }
createBuildStep(txn, 0, build, r, "", bssCachedFailure, "", propagatedFrom); createBuildStep(txn, 0, build, r, "", bsCachedFailure, "", propagatedFrom);
txn.parameterized txn.parameterized
("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $3, isCachedBuild = 1 where id = $1 and finished = 0") ("update Builds set finished = 1, buildStatus = $2, startTime = $3, stopTime = $3, isCachedBuild = 1 where id = $1 and finished = 0")
(build->id) (build->id)

View file

@ -26,27 +26,17 @@ typedef std::chrono::time_point<std::chrono::system_clock> system_time;
typedef enum { typedef enum {
bsSuccess = 0, bsSuccess = 0,
bsFailed = 1, bsFailed = 1,
bsDepFailed = 2, bsDepFailed = 2, // builds only
bsAborted = 3, bsAborted = 3,
bsFailedWithOutput = 6, bsFailedWithOutput = 6, // builds only
bsTimedOut = 7, bsTimedOut = 7,
bsCachedFailure = 8, // steps only
bsUnsupported = 9, bsUnsupported = 9,
bsLogLimitExceeded = 10, bsLogLimitExceeded = 10,
bsBusy = 100, // not stored
} BuildStatus; } BuildStatus;
typedef enum {
bssSuccess = 0,
bssFailed = 1,
bssAborted = 4,
bssTimedOut = 7,
bssCachedFailure = 8,
bssUnsupported = 9,
bssLogLimitExceeded = 10,
bssBusy = 100, // not stored
} BuildStepStatus;
struct RemoteResult : nix::BuildResult struct RemoteResult : nix::BuildResult
{ {
time_t startTime = 0, stopTime = 0; time_t startTime = 0, stopTime = 0;
@ -384,12 +374,12 @@ private:
int allocBuildStep(pqxx::work & txn, Build::ptr build); int allocBuildStep(pqxx::work & txn, Build::ptr build);
int createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step, int createBuildStep(pqxx::work & txn, time_t startTime, Build::ptr build, Step::ptr step,
const std::string & machine, BuildStepStatus status, const std::string & errorMsg = "", const std::string & machine, BuildStatus status, const std::string & errorMsg = "",
BuildID propagatedFrom = 0); BuildID propagatedFrom = 0);
void finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime, void finishBuildStep(pqxx::work & txn, time_t startTime, time_t stopTime,
unsigned int overhead, BuildID buildId, int stepNr, unsigned int overhead, BuildID buildId, int stepNr,
const std::string & machine, BuildStepStatus status, const std::string & errorMsg = "", const std::string & machine, BuildStatus status, const std::string & errorMsg = "",
BuildID propagatedFrom = 0); BuildID propagatedFrom = 0);
int createSubstitutionStep(pqxx::work & txn, time_t startTime, time_t stopTime, int createSubstitutionStep(pqxx::work & txn, time_t startTime, time_t stopTime,

View file

@ -55,7 +55,7 @@ FOR step IN steps; IF step.busy; busy = 1; END; END;
<strong>Building</strong> <strong>Building</strong>
[% ELSIF step.status == 0 %] [% ELSIF step.status == 0 %]
Succeeded Succeeded
[% ELSIF step.status == 4 %] [% ELSIF step.status == 3 %]
<span class="error"><strong>Aborted</strong>[% IF step.errormsg %]: [% HTML.escape(step.errormsg); END %]</span> <span class="error"><strong>Aborted</strong>[% IF step.errormsg %]: [% HTML.escape(step.errormsg); END %]</span>
[% ELSIF step.status == 7 %] [% ELSIF step.status == 7 %]
<span class="error">Timed out</span> <span class="error">Timed out</span>

View file

@ -195,7 +195,7 @@ BLOCK renderBuildStatusIcon;
<img src="[% c.uri_for("/static/images/checkmark_${size}.png") %]" alt="Succeeded" class="build-status" /> <img src="[% c.uri_for("/static/images/checkmark_${size}.png") %]" alt="Succeeded" class="build-status" />
[% ELSIF buildstatus == 1 %] [% ELSIF buildstatus == 1 %]
<img src="[% c.uri_for("/static/images/error_${size}.png") %]" alt="Failed" class="build-status" /> <img src="[% c.uri_for("/static/images/error_${size}.png") %]" alt="Failed" class="build-status" />
[% ELSIF buildstatus == 2 || buildstatus == 5 %] [% ELSIF buildstatus == 2 %]
<img src="[% c.uri_for("/static/images/dependency_${size}.png") %]" alt="Dependency failed" class="build-status" /> <img src="[% c.uri_for("/static/images/dependency_${size}.png") %]" alt="Dependency failed" class="build-status" />
[% ELSIF buildstatus == 3 || buildstatus == 9 %] [% ELSIF buildstatus == 3 || buildstatus == 9 %]
<img src="[% c.uri_for("/static/images/warning_${size}.png") %]" alt="Aborted" class="build-status" /> <img src="[% c.uri_for("/static/images/warning_${size}.png") %]" alt="Aborted" class="build-status" />
@ -224,7 +224,7 @@ BLOCK renderStatus;
<strong>Success</strong> <strong>Success</strong>
[% ELSIF buildstatus == 1 %] [% ELSIF buildstatus == 1 %]
<span class="error">Build returned a non-zero exit code</span> <span class="error">Build returned a non-zero exit code</span>
[% ELSIF buildstatus == 2 || buildstatus == 5 %] [% ELSIF buildstatus == 2 %]
<span class="error">A dependency of the build failed</span> <span class="error">A dependency of the build failed</span>
[% ELSIF buildstatus == 4 %] [% ELSIF buildstatus == 4 %]
<span class="error">Cancelled by user</span> <span class="error">Cancelled by user</span>

View file

@ -180,15 +180,16 @@ create table Builds (
-- Information about finished builds. -- Information about finished builds.
isCachedBuild integer, -- boolean isCachedBuild integer, -- boolean
-- Status codes: -- Status codes used for builds and steps:
-- 0 = succeeded -- 0 = succeeded
-- 1 = build of this derivation failed -- 1 = regular Nix failure (derivation returned non-zero exit code)
-- 2 = build of some dependency failed -- 2 = build of a dependency failed [builds only]
-- 3 = other failure -- 3 = build or step aborted due to misc failure
-- 4 = build cancelled (removed from queue; never built) -- 4 = build cancelled (removed from queue; never built) [builds only]
-- 5 = build not done because a dependency failed previously (obsolete) -- 5 = [obsolete]
-- 6 = failure with output -- 6 = failure with output (i.e. $out/nix-support/failed exists) [builds only]
-- 7 = timed out -- 7 = build timed out
-- 8 = cached failure [steps only; builds use isCachedBuild]
-- 9 = unsupported system type -- 9 = unsupported system type
-- 10 = log limit exceeded -- 10 = log limit exceeded
buildStatus integer, buildStatus integer,
@ -253,15 +254,7 @@ create table BuildSteps (
busy integer not null, busy integer not null,
-- Status codes: status integer, -- see Builds.buildStatus
-- 0 = succeeded
-- 1 = failed normally
-- 4 = aborted
-- 7 = timed out
-- 8 = cached failure
-- 9 = unsupported system type
-- 10 = log limit exceeded
status integer,
errorMsg text, errorMsg text,

5
src/sql/upgrade-46.sql Normal file
View file

@ -0,0 +1,5 @@
-- Unify Builds and BuildSteps status codes.
update BuildSteps set status = 3 where status = 4;
-- Get rid of obsolete status code 5.
update Builds set isCachedBuild = 1, buildStatus = 2 where buildStatus = 5;