Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
12242 views
1
<?php
2
3
final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
4
5
protected function run() {
6
do {
7
PhabricatorCaches::destroyRequestCache();
8
9
$tasks = id(new PhabricatorWorkerLeaseQuery())
10
->setLimit(1)
11
->execute();
12
13
if ($tasks) {
14
$this->willBeginWork();
15
16
foreach ($tasks as $task) {
17
$id = $task->getID();
18
$class = $task->getTaskClass();
19
20
$this->log(pht('Working on task %d (%s)...', $id, $class));
21
22
$task = $task->executeTask();
23
$ex = $task->getExecutionException();
24
if ($ex) {
25
if ($ex instanceof PhabricatorWorkerPermanentFailureException) {
26
// NOTE: Make sure these reach the daemon log, even when not
27
// running in verbose mode. See T12803 for discussion.
28
$log_exception = new PhutilProxyException(
29
pht(
30
'Task "%s" encountered a permanent failure and was '.
31
'cancelled.',
32
$id),
33
$ex);
34
phlog($log_exception);
35
} else if ($ex instanceof PhabricatorWorkerYieldException) {
36
$this->log(pht('Task %s yielded.', $id));
37
} else {
38
$this->log(pht('Task %d failed!', $id));
39
throw new PhutilProxyException(
40
pht('Error while executing Task ID %d.', $id),
41
$ex);
42
}
43
} else {
44
$this->log(pht('Task %s complete! Moved to archive.', $id));
45
}
46
}
47
48
$sleep = 0;
49
} else {
50
51
if ($this->getIdleDuration() > 15) {
52
$hibernate_duration = phutil_units('3 minutes in seconds');
53
if ($this->shouldHibernate($hibernate_duration)) {
54
break;
55
}
56
}
57
58
// When there's no work, sleep for one second. The pool will
59
// autoscale down if we're continuously idle for an extended period
60
// of time.
61
$this->willBeginIdle();
62
$sleep = 1;
63
}
64
65
$this->sleep($sleep);
66
} while (!$this->shouldExit());
67
}
68
69
}
70
71