Differential D8774 Diff 20827 src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | public function archiveTask($result, $duration) { | ||||
return $archive; | return $archive; | ||||
} | } | ||||
public function executeTask() { | public function executeTask() { | ||||
// We do this outside of the try .. catch because we don't have permission | // We do this outside of the try .. catch because we don't have permission | ||||
// to release the lease otherwise. | // to release the lease otherwise. | ||||
$this->checkLease(); | $this->checkLease(); | ||||
$did_succeed = false; | |||||
try { | try { | ||||
$worker = $this->getWorkerInstance(); | $worker = $this->getWorkerInstance(); | ||||
$maximum_failures = $worker->getMaximumRetryCount(); | $maximum_failures = $worker->getMaximumRetryCount(); | ||||
if ($maximum_failures !== null) { | if ($maximum_failures !== null) { | ||||
if ($this->getFailureCount() > $maximum_failures) { | if ($this->getFailureCount() > $maximum_failures) { | ||||
$id = $this->getID(); | $id = $this->getID(); | ||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
Show All 10 Lines | try { | ||||
$t_start = microtime(true); | $t_start = microtime(true); | ||||
$worker->executeTask(); | $worker->executeTask(); | ||||
$t_end = microtime(true); | $t_end = microtime(true); | ||||
$duration = (int)(1000000 * ($t_end - $t_start)); | $duration = (int)(1000000 * ($t_end - $t_start)); | ||||
$result = $this->archiveTask( | $result = $this->archiveTask( | ||||
PhabricatorWorkerArchiveTask::RESULT_SUCCESS, | PhabricatorWorkerArchiveTask::RESULT_SUCCESS, | ||||
$duration); | $duration); | ||||
$did_succeed = true; | |||||
} catch (PhabricatorWorkerPermanentFailureException $ex) { | } catch (PhabricatorWorkerPermanentFailureException $ex) { | ||||
$result = $this->archiveTask( | $result = $this->archiveTask( | ||||
PhabricatorWorkerArchiveTask::RESULT_FAILURE, | PhabricatorWorkerArchiveTask::RESULT_FAILURE, | ||||
0); | 0); | ||||
$result->setExecutionException($ex); | $result->setExecutionException($ex); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$this->setExecutionException($ex); | $this->setExecutionException($ex); | ||||
$this->setFailureCount($this->getFailureCount() + 1); | $this->setFailureCount($this->getFailureCount() + 1); | ||||
$this->setFailureTime(time()); | $this->setFailureTime(time()); | ||||
$retry = $worker->getWaitBeforeRetry($this); | $retry = $worker->getWaitBeforeRetry($this); | ||||
$retry = coalesce( | $retry = coalesce( | ||||
$retry, | $retry, | ||||
PhabricatorWorkerLeaseQuery::DEFAULT_LEASE_DURATION); | PhabricatorWorkerLeaseQuery::getDefaultWaitBeforeRetry()); | ||||
// NOTE: As a side effect, this saves the object. | // NOTE: As a side effect, this saves the object. | ||||
$this->setLeaseDuration($retry); | $this->setLeaseDuration($retry); | ||||
$result = $this; | $result = $this; | ||||
} | } | ||||
// NOTE: If this throws, we don't want it to cause the task to fail again, | |||||
// so execute it out here and just let the exception escape. | |||||
if ($did_succeed) { | |||||
foreach ($worker->getQueuedTasks() as $task) { | |||||
list($class, $data) = $task; | |||||
PhabricatorWorker::scheduleTask($class, $data); | |||||
} | |||||
} | |||||
return $result; | return $result; | ||||
} | } | ||||
} | } |