blob: cf52280ed7d90c950b77d93e09ee20ae491ab011 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "goal.hh"
#include "async-collect.hh"
#include "worker.hh"
#include <boost/outcome/try.hpp>
#include <kj/time.h>
namespace nix {
void Goal::trace(std::string_view s)
{
debug("%1%: %2%", name, s);
}
kj::Promise<void> Goal::waitForAWhile()
{
trace("wait for a while");
/* If we are polling goals that are waiting for a lock, then wake
up after a few seconds at most. */
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(result);
cleanup();
co_return std::move(result);
} catch (...) {
co_return result::failure(std::current_exception());
}
kj::Promise<Result<void>>
Goal::waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<Result<WorkResult>>>> dependencies) noexcept
try {
auto left = dependencies.size();
for (auto & [dep, p] : dependencies) {
p = p.then([this, dep, &left](auto _result) {
left--;
trace(fmt("waitee '%s' done; %d left", dep->name, left));
if (dep->exitCode != Goal::ecSuccess) ++nrFailed;
if (dep->exitCode == Goal::ecNoSubstituters) ++nrNoSubstituters;
if (dep->exitCode == Goal::ecIncompleteClosure) ++nrIncompleteClosure;
return _result;
}).eagerlyEvaluate(nullptr);
}
auto collectDeps = asyncCollect(std::move(dependencies));
while (auto item = co_await collectDeps.next()) {
auto & [dep, _result] = *item;
waiteeDone(dep);
if (dep->exitCode == ecFailed && !settings.keepGoing) {
co_return result::success();
}
}
co_return result::success();
} catch (...) {
co_return result::failure(std::current_exception());
}
}
|