Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
<?php | <?php | ||||
final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon { | final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon { | ||||
protected function run() { | protected function run() { | ||||
$taskmaster_count = PhabricatorEnv::getEnvConfig('phd.start-taskmasters'); | $taskmaster_count = PhabricatorEnv::getEnvConfig('phd.start-taskmasters'); | ||||
$offset = mt_rand(0, $taskmaster_count - 1); | $offset = mt_rand(0, $taskmaster_count - 1); | ||||
do { | do { | ||||
$tasks = id(new PhabricatorWorkerLeaseQuery()) | $tasks = id(new PhabricatorWorkerLeaseQuery()) | ||||
->setLimit(1) | ->setLimit(1) | ||||
->execute(); | ->execute(); | ||||
if ($tasks) { | if ($tasks) { | ||||
$this->willBeginWork(); | |||||
foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
$id = $task->getID(); | $id = $task->getID(); | ||||
$class = $task->getTaskClass(); | $class = $task->getTaskClass(); | ||||
$this->log("Working on task {$id} ({$class})..."); | $this->log("Working on task {$id} ({$class})..."); | ||||
$task = $task->executeTask(); | $task = $task->executeTask(); | ||||
$ex = $task->getExecutionException(); | $ex = $task->getExecutionException(); | ||||
Show All 27 Lines | do { | ||||
// without much work to do. | // without much work to do. | ||||
// It also means an empty queue has an average load of one query | // It also means an empty queue has an average load of one query | ||||
// per second even if there are a very large number of taskmasters | // per second even if there are a very large number of taskmasters | ||||
// launched. | // launched. | ||||
// The first time we sleep, we add a random offset to try to spread | // The first time we sleep, we add a random offset to try to spread | ||||
// the sleep times out somewhat evenly. | // the sleep times out somewhat evenly. | ||||
$this->willBeginIdle(); | |||||
$sleep = $taskmaster_count + $offset; | $sleep = $taskmaster_count + $offset; | ||||
$offset = 0; | $offset = 0; | ||||
} | } | ||||
$this->sleep($sleep); | $this->sleep($sleep); | ||||
} while (!$this->shouldExit()); | } while (!$this->shouldExit()); | ||||
} | } | ||||
} | } |