<?php

final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {

  public function run() {
    $sleep = 0;
    do {
      $tasks = id(new PhabricatorWorkerLeaseQuery())
        ->setLimit(1)
        ->execute();

      if ($tasks) {
        foreach ($tasks as $task) {
          $id = $task->getID();
          $class = $task->getTaskClass();

          $this->log("Working on task {$id} ({$class})...");

          $task = $task->executeTask();
          $ex = $task->getExecutionException();
          if ($ex) {
            if ($ex instanceof PhabricatorWorkerPermanentFailureException) {
              $this->log("Task {$id} failed permanently.");
            } else {
              $this->log("Task {$id} failed!");
              throw $ex;
            }
          } else {
            $this->log("Task {$id} complete! Moved to archive.");
          }
        }

        $sleep = 0;
      } else {
        $sleep = min($sleep + 1, 30);
      }

      $this->sleep($sleep);
    } while (true);
  }

}

<?php

final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {

  public function run() {
    $sleep = 0;
    do {
      $tasks = id(new PhabricatorWorkerLeaseQuery())
        ->setLimit(1)
        ->execute();

      if ($tasks) {
        foreach ($tasks as $task) {
          $id = $task->getID();
          $class = $task->getTaskClass();

          $this->log("Working on task {$id} ({$class})...");

          $task = $task->executeTask();
          $ex = $task->getExecutionException();
          if ($ex) {
            if ($ex instanceof PhabricatorWorkerPermanentFailureException) {
              $this->log("Task {$id} failed permanently.");
            } else {
              $this->log("Task {$id} failed!");
              throw new PhutilProxyException(
                "Error while executing task ID {$id} from queue.",
                $ex);
            }
          } else {
            $this->log("Task {$id} complete! Moved to archive.");
          }
        }

        $sleep = 0;
      } else {
        $sleep = min($sleep + 1, 30);
      }

      $this->sleep($sleep);
    } while (true);
  }

}

Use PhutilProxyException to disambiguate work queue failures
Use PhutilProxyException to disambiguate work queue failures

Summary: Fixes T2569. This is the other common exception source which is ambiguous. List the task ID explicitly to make debugging easier.

Test Plan: {F51268}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2569

Differential Revision: https://secure.phabricator.com/D6549
