Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/PhabricatorWorker.php
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | final public static function scheduleTask( | ||||
if (self::$runAllTasksInProcess) { | if (self::$runAllTasksInProcess) { | ||||
// Do the work in-process. | // Do the work in-process. | ||||
$worker = newv($task_class, array($data)); | $worker = newv($task_class, array($data)); | ||||
while (true) { | while (true) { | ||||
try { | try { | ||||
$worker->executeTask(); | $worker->executeTask(); | ||||
$worker->flushTaskQueue(); | $worker->flushTaskQueue(); | ||||
$task_result = PhabricatorWorkerArchiveTask::RESULT_SUCCESS; | |||||
break; | |||||
} catch (PhabricatorWorkerPermanentFailureException $ex) { | |||||
$proxy = new PhutilProxyException( | |||||
pht( | |||||
'In-process task ("%s") failed permanently.', | |||||
$task_class), | |||||
$ex); | |||||
phlog($proxy); | |||||
$task_result = PhabricatorWorkerArchiveTask::RESULT_FAILURE; | |||||
break; | break; | ||||
} catch (PhabricatorWorkerYieldException $ex) { | } catch (PhabricatorWorkerYieldException $ex) { | ||||
phlog( | phlog( | ||||
pht( | pht( | ||||
'In-process task "%s" yielded for %s seconds, sleeping...', | 'In-process task "%s" yielded for %s seconds, sleeping...', | ||||
$task_class, | $task_class, | ||||
$ex->getDuration())); | $ex->getDuration())); | ||||
sleep($ex->getDuration()); | sleep($ex->getDuration()); | ||||
} | } | ||||
} | } | ||||
// Now, save a task row and immediately archive it so we can return an | // Now, save a task row and immediately archive it so we can return an | ||||
// object with a valid ID. | // object with a valid ID. | ||||
$task->openTransaction(); | $task->openTransaction(); | ||||
$task->save(); | $task->save(); | ||||
$archived = $task->archiveTask( | $archived = $task->archiveTask($task_result, 0); | ||||
PhabricatorWorkerArchiveTask::RESULT_SUCCESS, | |||||
0); | |||||
$task->saveTransaction(); | $task->saveTransaction(); | ||||
return $archived; | return $archived; | ||||
} else { | } else { | ||||
$task->save(); | $task->save(); | ||||
return $task; | return $task; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |