Path: blob/master/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
12242 views
<?php12final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {34protected function run() {5do {6PhabricatorCaches::destroyRequestCache();78$tasks = id(new PhabricatorWorkerLeaseQuery())9->setLimit(1)10->execute();1112if ($tasks) {13$this->willBeginWork();1415foreach ($tasks as $task) {16$id = $task->getID();17$class = $task->getTaskClass();1819$this->log(pht('Working on task %d (%s)...', $id, $class));2021$task = $task->executeTask();22$ex = $task->getExecutionException();23if ($ex) {24if ($ex instanceof PhabricatorWorkerPermanentFailureException) {25// NOTE: Make sure these reach the daemon log, even when not26// running in verbose mode. See T12803 for discussion.27$log_exception = new PhutilProxyException(28pht(29'Task "%s" encountered a permanent failure and was '.30'cancelled.',31$id),32$ex);33phlog($log_exception);34} else if ($ex instanceof PhabricatorWorkerYieldException) {35$this->log(pht('Task %s yielded.', $id));36} else {37$this->log(pht('Task %d failed!', $id));38throw new PhutilProxyException(39pht('Error while executing Task ID %d.', $id),40$ex);41}42} else {43$this->log(pht('Task %s complete! Moved to archive.', $id));44}45}4647$sleep = 0;48} else {4950if ($this->getIdleDuration() > 15) {51$hibernate_duration = phutil_units('3 minutes in seconds');52if ($this->shouldHibernate($hibernate_duration)) {53break;54}55}5657// When there's no work, sleep for one second. The pool will58// autoscale down if we're continuously idle for an extended period59// of time.60$this->willBeginIdle();61$sleep = 1;62}6364$this->sleep($sleep);65} while (!$this->shouldExit());66}6768}697071