@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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 Exception(
29 pht(
30 'Task "%s" encountered a permanent failure and was '.
31 'cancelled.',
32 $id),
33 0,
34 $ex);
35 phlog($log_exception);
36 } else if ($ex instanceof PhabricatorWorkerYieldException) {
37 $this->log(pht('Task %s yielded.', $id));
38 } else {
39 $this->log(pht('Task %d failed!', $id));
40 throw new Exception(
41 pht('Error while executing Task ID %d.', $id),
42 0,
43 $ex);
44 }
45 } else {
46 $this->log(pht('Task %s complete! Moved to archive.', $id));
47 }
48 }
49
50 $sleep = 0;
51 } else {
52
53 if ($this->getIdleDuration() > 15) {
54 $hibernate_duration = phutil_units('3 minutes in seconds');
55 if ($this->shouldHibernate($hibernate_duration)) {
56 break;
57 }
58 }
59
60 // When there's no work, sleep for one second. The pool will
61 // autoscale down if we're continuously idle for an extended period
62 // of time.
63 $this->willBeginIdle();
64 $sleep = 1;
65 }
66
67 $this->sleep($sleep);
68 } while (!$this->shouldExit());
69 }
70
71}