[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/daemon/controller/ -> PhabricatorWorkerTaskUpdateController.php (source)

   1  <?php
   2  
   3  final class PhabricatorWorkerTaskUpdateController
   4    extends PhabricatorDaemonController {
   5  
   6    private $id;
   7    private $action;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->id = $data['id'];
  11      $this->action = $data['action'];
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16      $user = $request->getUser();
  17  
  18      $task = id(new PhabricatorWorkerActiveTask())->load($this->id);
  19      if (!$task) {
  20        $task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
  21      }
  22  
  23      if (!$task) {
  24        return new Aphront404Response();
  25      }
  26  
  27      $result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
  28      $can_retry = ($task->isArchived()) &&
  29                   ($task->getResult() != $result_success);
  30  
  31      $can_cancel = !$task->isArchived();
  32      $can_release = (!$task->isArchived()) &&
  33                     ($task->getLeaseOwner());
  34  
  35      $next_uri = $this->getApplicationURI('/task/'.$task->getID().'/');
  36  
  37      if ($request->isFormPost()) {
  38        switch ($this->action) {
  39          case 'retry':
  40            if ($can_retry) {
  41              $task->unarchiveTask();
  42            }
  43            break;
  44          case 'cancel':
  45            if ($can_cancel) {
  46              // Forcibly break the lease if one exists, so we can archive the
  47              // task.
  48              $task->setLeaseOwner(null);
  49              $task->setLeaseExpires(time());
  50  
  51              $task->archiveTask(
  52                PhabricatorWorkerArchiveTask::RESULT_CANCELLED,
  53                0);
  54            }
  55            break;
  56          case 'release':
  57            if ($can_release) {
  58              $task->setLeaseOwner(null);
  59              $task->setLeaseExpires(time());
  60              $task->save();
  61            }
  62            break;
  63        }
  64        return id(new AphrontRedirectResponse())
  65          ->setURI($next_uri);
  66      }
  67  
  68      $dialog = new AphrontDialogView();
  69      $dialog->setUser($user);
  70  
  71      switch ($this->action) {
  72        case 'retry':
  73          if ($can_retry) {
  74            $dialog->setTitle(pht('Really retry task?'));
  75            $dialog->appendChild(phutil_tag('p', array(), pht(
  76              'The task will be put back in the queue and executed again.')));
  77            $dialog->addSubmitButton('Retry Task');
  78          } else {
  79            $dialog->setTitle(pht('Can Not Retry'));
  80            $dialog->appendChild(phutil_tag('p', array(), pht(
  81              'Only archived, unsuccessful tasks can be retried.')));
  82          }
  83          break;
  84        case 'cancel':
  85          if ($can_cancel) {
  86            $dialog->setTitle(pht('Really cancel task?'));
  87            $dialog->appendChild(phutil_tag('p', array(), pht(
  88              'The work this task represents will never be performed if you '.
  89              'cancel it. Are you sure you want to cancel it?')));
  90            $dialog->addSubmitButton(pht('Cancel Task'));
  91          } else {
  92            $dialog->setTitle(pht('Cannot Cancel'));
  93            $dialog->appendChild(phutil_tag('p', array(), pht(
  94              'Only active tasks can be cancelled.')));
  95          }
  96          break;
  97        case 'release':
  98          if ($can_release) {
  99            $dialog->setTitle(pht('Really free task lease?'));
 100            $dialog->appendChild(phutil_tag('p', array(), pht(
 101              'If the process which owns the task lease is still doing work '.
 102              'on it, the work may be performed twice. Are you sure you '.
 103              'want to free the lease?')));
 104            $dialog->addSubmitButton(pht('Free Lease'));
 105          } else {
 106            $dialog->setTitle(pht('Cannot Free Lease'));
 107            $dialog->appendChild(phutil_tag('p', array(), pht(
 108              'Only active, leased tasks may have their leases freed.')));
 109          }
 110          break;
 111        default:
 112          return new Aphront404Response();
 113      }
 114  
 115      $dialog->addCancelButton($next_uri);
 116  
 117      return id(new AphrontDialogResponse())->setDialog($dialog);
 118    }
 119  
 120  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1