forked from lix-project/lix
libstore: extract Worker::goalFinished specifics
there's no reason to have the worker set information on goals that the
goals themselves return from their entry point. doing this in the goal
`work()` function is much cleaner, and a prerequisite to removing more
implicit strong shared references to goals that are currently running.
Change-Id: Ibb3e953ab8482a6a21ce2ed659d5023a991e7923
This commit is contained in:
parent
99edc2ae38
commit
a9f2aab226
|
@ -125,7 +125,7 @@ Goal::WorkResult DerivationGoal::timedOut(Error && ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DerivationGoal::work() noexcept
|
kj::Promise<Result<Goal::WorkResult>> DerivationGoal::workImpl() noexcept
|
||||||
{
|
{
|
||||||
return useDerivation ? getDerivation() : haveDerivation();
|
return useDerivation ? getDerivation() : haveDerivation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ struct DerivationGoal : public Goal
|
||||||
|
|
||||||
WorkResult timedOut(Error && ex);
|
WorkResult timedOut(Error && ex);
|
||||||
|
|
||||||
kj::Promise<Result<WorkResult>> work() noexcept override;
|
kj::Promise<Result<WorkResult>> workImpl() noexcept override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add wanted outputs to an already existing derivation goal.
|
* Add wanted outputs to an already existing derivation goal.
|
||||||
|
|
|
@ -24,7 +24,7 @@ DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::work() noexcept
|
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::workImpl() noexcept
|
||||||
try {
|
try {
|
||||||
trace("init");
|
trace("init");
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
kj::Promise<Result<WorkResult>> outPathValid() noexcept;
|
kj::Promise<Result<WorkResult>> outPathValid() noexcept;
|
||||||
kj::Promise<Result<WorkResult>> finished() noexcept;
|
kj::Promise<Result<WorkResult>> finished() noexcept;
|
||||||
|
|
||||||
kj::Promise<Result<WorkResult>> work() noexcept override;
|
kj::Promise<Result<WorkResult>> workImpl() noexcept override;
|
||||||
|
|
||||||
JobCategory jobCategory() const override {
|
JobCategory jobCategory() const override {
|
||||||
return JobCategory::Substitution;
|
return JobCategory::Substitution;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "goal.hh"
|
#include "goal.hh"
|
||||||
#include "async-collect.hh"
|
#include "async-collect.hh"
|
||||||
#include "worker.hh"
|
#include "worker.hh"
|
||||||
|
#include <boost/outcome/try.hpp>
|
||||||
#include <kj/time.h>
|
#include <kj/time.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -19,6 +20,23 @@ kj::Promise<void> Goal::waitForAWhile()
|
||||||
return worker.aio.provider->getTimer().afterDelay(settings.pollInterval.get() * kj::SECONDS);
|
return worker.aio.provider->getTimer().afterDelay(settings.pollInterval.get() * kj::SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kj::Promise<Result<Goal::WorkResult>> Goal::work() noexcept
|
||||||
|
try {
|
||||||
|
BOOST_OUTCOME_CO_TRY(auto result, co_await workImpl());
|
||||||
|
|
||||||
|
trace("done");
|
||||||
|
assert(!exitCode.has_value());
|
||||||
|
exitCode = result.exitCode;
|
||||||
|
ex = result.ex;
|
||||||
|
|
||||||
|
notify->fulfill();
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
co_return std::move(result);
|
||||||
|
} catch (...) {
|
||||||
|
co_return result::failure(std::current_exception());
|
||||||
|
}
|
||||||
|
|
||||||
kj::Promise<Result<void>>
|
kj::Promise<Result<void>>
|
||||||
Goal::waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<void>>> dependencies) noexcept
|
Goal::waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<void>>> dependencies) noexcept
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -92,7 +92,7 @@ struct Goal
|
||||||
*/
|
*/
|
||||||
BuildResult buildResult;
|
BuildResult buildResult;
|
||||||
|
|
||||||
// for use by Worker only. will go away once work() is a promise.
|
// for use by Worker and Goal only. will go away once work() is a promise.
|
||||||
kj::Own<kj::PromiseFulfiller<void>> notify;
|
kj::Own<kj::PromiseFulfiller<void>> notify;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -121,6 +121,8 @@ protected:
|
||||||
return waitForGoals(kj::arrOf<std::pair<GoalPtr, kj::Promise<void>>>(std::move(goals)...));
|
return waitForGoals(kj::arrOf<std::pair<GoalPtr, kj::Promise<void>>>(std::move(goals)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual kj::Promise<Result<WorkResult>> workImpl() noexcept = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,7 +140,7 @@ public:
|
||||||
trace("goal destroyed");
|
trace("goal destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual kj::Promise<Result<WorkResult>> work() noexcept = 0;
|
kj::Promise<Result<WorkResult>> work() noexcept;
|
||||||
|
|
||||||
virtual void waiteeDone(GoalPtr waitee) { }
|
virtual void waiteeDone(GoalPtr waitee) { }
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ Goal::WorkResult PathSubstitutionGoal::done(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> PathSubstitutionGoal::work() noexcept
|
kj::Promise<Result<Goal::WorkResult>> PathSubstitutionGoal::workImpl() noexcept
|
||||||
try {
|
try {
|
||||||
trace("init");
|
trace("init");
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ public:
|
||||||
);
|
);
|
||||||
~PathSubstitutionGoal();
|
~PathSubstitutionGoal();
|
||||||
|
|
||||||
kj::Promise<Result<WorkResult>> work() noexcept override;
|
kj::Promise<Result<WorkResult>> workImpl() noexcept override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The states.
|
* The states.
|
||||||
|
|
|
@ -195,19 +195,12 @@ static void removeGoal(std::shared_ptr<G> goal, auto & goalMap)
|
||||||
|
|
||||||
void Worker::goalFinished(GoalPtr goal, Goal::WorkResult & f)
|
void Worker::goalFinished(GoalPtr goal, Goal::WorkResult & f)
|
||||||
{
|
{
|
||||||
goal->trace("done");
|
|
||||||
assert(!goal->exitCode.has_value());
|
|
||||||
goal->exitCode = f.exitCode;
|
|
||||||
goal->ex = f.ex;
|
|
||||||
|
|
||||||
permanentFailure |= f.permanentFailure;
|
permanentFailure |= f.permanentFailure;
|
||||||
timedOut |= f.timedOut;
|
timedOut |= f.timedOut;
|
||||||
hashMismatch |= f.hashMismatch;
|
hashMismatch |= f.hashMismatch;
|
||||||
checkMismatch |= f.checkMismatch;
|
checkMismatch |= f.checkMismatch;
|
||||||
|
|
||||||
removeGoal(goal);
|
removeGoal(goal);
|
||||||
goal->notify->fulfill();
|
|
||||||
goal->cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker::removeGoal(GoalPtr goal)
|
void Worker::removeGoal(GoalPtr goal)
|
||||||
|
|
Loading…
Reference in a new issue