Modernize worker task detail view

Summary: Make mobile-friendly and provide UI to cancel/retry tasks. Remove display of task data to arbitrary users, as it may be sensitive.

Test Plan:
{F22502}
{F22503}
{F22504}
{F22505}
{F22506}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D3854
This commit is contained in:
epriestley
2012-10-31 15:22:32 -07:00
parent 5903ed650c
commit fe329b9738
8 changed files with 270 additions and 147 deletions

View File

@@ -32,48 +32,104 @@ final class PhabricatorWorkerTaskUpdateController
$user = $request->getUser();
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
if (!$task) {
$task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
}
if (!$task) {
return new Aphront404Response();
}
$result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
$can_retry = ($task->isArchived()) &&
($task->getResult() != $result_success);
$can_cancel = !$task->isArchived();
$can_release = (!$task->isArchived()) &&
($task->getLeaseOwner());
$next_uri = $this->getApplicationURI('/task/'.$task->getID().'/');
if ($request->isFormPost()) {
switch ($this->action) {
case 'delete':
$task->delete();
case 'retry':
if ($can_retry) {
$task->unarchiveTask();
}
break;
case 'cancel':
if ($can_cancel) {
// Forcibly break the lease if one exists, so we can archive the
// task.
$task->setLeaseOwner(null);
$task->setLeaseExpires(time());
$task->archiveTask(
PhabricatorWorkerArchiveTask::RESULT_CANCELLED,
0);
}
break;
case 'release':
$task->setLeaseOwner(null);
$task->setLeaseExpires(time());
$task->save();
if ($can_release) {
$task->setLeaseOwner(null);
$task->setLeaseExpires(time());
$task->save();
}
break;
}
return id(new AphrontRedirectResponse())->setURI('/daemon/');
return id(new AphrontRedirectResponse())
->setURI($next_uri);
}
$dialog = new AphrontDialogView();
$dialog->setUser($user);
switch ($this->action) {
case 'delete':
$dialog->setTitle('Really delete task?');
$dialog->appendChild(
'<p>The work this task represents will never be performed if you '.
'delete it. Are you sure you want to delete it?</p>');
$dialog->addSubmitButton('Delete Task');
case 'retry':
if ($can_retry) {
$dialog->setTitle('Really retry task?');
$dialog->appendChild(
'<p>The task will be put back in the queue and executed '.
'again.</p>');
$dialog->addSubmitButton('Retry Task');
} else {
$dialog->setTitle('Can Not Retry');
$dialog->appendChild(
'<p>Only archived, unsuccessful tasks can be retried.</p>');
}
break;
case 'cancel':
if ($can_cancel) {
$dialog->setTitle('Really cancel task?');
$dialog->appendChild(
'<p>The work this task represents will never be performed if you '.
'cancel it. Are you sure you want to cancel it?</p>');
$dialog->addSubmitButton('Cancel Task');
} else {
$dialog->setTitle('Can Not Cancel');
$dialog->appendChild(
'<p>Only active tasks can be cancelled.</p>');
}
break;
case 'release':
$dialog->setTitle('Really free task lease?');
$dialog->appendChild(
'<p>If the process which owns the task lease is still doing work '.
'on it, the work may be performed twice. Are you sure you '.
'want to free the lease?</p>');
$dialog->addSubmitButton('Free Lease');
if ($can_release) {
$dialog->setTitle('Really free task lease?');
$dialog->appendChild(
'<p>If the process which owns the task lease is still doing work '.
'on it, the work may be performed twice. Are you sure you '.
'want to free the lease?</p>');
$dialog->addSubmitButton('Free Lease');
} else {
$dialog->setTitle('Can Not Free Lease');
$dialog->appendChild(
'<p>Only active, leased tasks may have their leases freed.</p>');
}
break;
default:
return new Aphront404Response();
}
$dialog->addCancelButton('/daemon/');
$dialog->addCancelButton($next_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}