2011-03-27 07:55:18 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorWorkerTaskDetailController
|
2011-03-27 07:55:18 +02:00
|
|
|
extends PhabricatorDaemonController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-10-31 23:22:16 +01:00
|
|
|
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
|
2011-03-27 07:55:18 +02:00
|
|
|
if (!$task) {
|
2012-10-31 23:22:32 +01:00
|
|
|
$task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$task) {
|
|
|
|
$title = pht('Task Does Not Exist');
|
|
|
|
|
2011-03-27 07:55:18 +02:00
|
|
|
$error_view = new AphrontErrorView();
|
2013-02-27 04:51:36 +01:00
|
|
|
$error_view->setTitle(pht('No Such Task'));
|
2013-02-07 01:53:49 +01:00
|
|
|
$error_view->appendChild(phutil_tag(
|
|
|
|
'p',
|
|
|
|
array(),
|
2013-02-27 04:51:36 +01:00
|
|
|
pht('This task may have recently been garbage collected.')));
|
2012-10-31 23:22:32 +01:00
|
|
|
$error_view->setSeverity(AphrontErrorView::SEVERITY_NODATA);
|
2011-03-27 07:55:18 +02:00
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
$content = $error_view;
|
|
|
|
} else {
|
2013-02-27 04:51:36 +01:00
|
|
|
$title = pht('Task %d', $task->getID());
|
Improve several Diffusion UI error states
Summary:
Give users better errors and UI:
- For subpath SVN repositories, default the path to the subdirectory, not to
"/". This makes the home screen useful and things generally less confusing.
- For unparsed commits, show a more descriptive error message without the
"blah blah" silliness.
- For paths outside of the subpath parse tree, short circuit into an
appropriate error message.
- For foreign SVN stub commits (see D892), show an explicit message.
Test Plan: Looked at unparsed commits, subpath repositories, foreign stub
commits, and paths outside of the subpath parse tree. Received sensible error
messages.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 894
2011-09-04 23:39:52 +02:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2013-02-27 04:51:36 +01:00
|
|
|
->setHeader(pht('Task %d (%s)',
|
|
|
|
$task->getID(),
|
|
|
|
$task->getTaskClass()));
|
2011-03-27 07:55:18 +02:00
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
$actions = $this->buildActionListView($task);
|
|
|
|
$properties = $this->buildPropertyListView($task);
|
Improve several Diffusion UI error states
Summary:
Give users better errors and UI:
- For subpath SVN repositories, default the path to the subdirectory, not to
"/". This makes the home screen useful and things generally less confusing.
- For unparsed commits, show a more descriptive error message without the
"blah blah" silliness.
- For paths outside of the subpath parse tree, short circuit into an
appropriate error message.
- For foreign SVN stub commits (see D892), show an explicit message.
Test Plan: Looked at unparsed commits, subpath repositories, foreign stub
commits, and paths outside of the subpath parse tree. Received sensible error
messages.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 894
2011-09-04 23:39:52 +02:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$retry_head = id(new PHUIHeaderView())
|
2013-07-08 23:34:18 +02:00
|
|
|
->setHeader(pht('Retries'));
|
|
|
|
|
|
|
|
$retry_info = $this->buildRetryListView($task);
|
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
$content = array(
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
2013-07-08 23:34:18 +02:00
|
|
|
$retry_head,
|
|
|
|
$retry_info,
|
2012-10-31 23:22:32 +01:00
|
|
|
);
|
|
|
|
}
|
2012-01-24 01:36:32 +01:00
|
|
|
|
2013-07-08 23:34:18 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($title));
|
2012-08-14 00:27:45 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
2013-07-08 23:34:18 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$content,
|
|
|
|
),
|
2011-03-27 07:55:18 +02:00
|
|
|
array(
|
2012-10-31 23:22:32 +01:00
|
|
|
'title' => $title,
|
2013-07-08 23:34:18 +02:00
|
|
|
'device' => true,
|
2011-03-27 07:55:18 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
private function buildActionListView(PhabricatorWorkerTask $task) {
|
2013-07-12 20:39:47 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2012-10-31 23:22:32 +01:00
|
|
|
$id = $task->getID();
|
|
|
|
|
2013-07-12 20:39:47 +02:00
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($user)
|
|
|
|
->setObjectURI($request->getRequestURI());
|
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
if ($task->isArchived()) {
|
|
|
|
$result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS;
|
|
|
|
$can_retry = ($task->getResult() != $result_success);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Retry Task'))
|
|
|
|
->setHref($this->getApplicationURI('/task/'.$id.'/retry/'))
|
|
|
|
->setIcon('undo')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_retry));
|
|
|
|
} else {
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Cancel Task'))
|
|
|
|
->setHref($this->getApplicationURI('/task/'.$id.'/cancel/'))
|
|
|
|
->setIcon('delete')
|
|
|
|
->setWorkflow(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
$can_release = (!$task->isArchived()) &&
|
|
|
|
($task->getLeaseOwner());
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Free Lease'))
|
|
|
|
->setHref($this->getApplicationURI('/task/'.$id.'/release/'))
|
|
|
|
->setIcon('unlock')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_release));
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyListView(PhabricatorWorkerTask $task) {
|
|
|
|
$view = new PhabricatorPropertyListView();
|
|
|
|
|
|
|
|
if ($task->isArchived()) {
|
|
|
|
switch ($task->getResult()) {
|
|
|
|
case PhabricatorWorkerArchiveTask::RESULT_SUCCESS:
|
|
|
|
$status = pht('Complete');
|
|
|
|
break;
|
|
|
|
case PhabricatorWorkerArchiveTask::RESULT_FAILURE:
|
|
|
|
$status = pht('Failed');
|
|
|
|
break;
|
|
|
|
case PhabricatorWorkerArchiveTask::RESULT_CANCELLED:
|
|
|
|
$status = pht('Cancelled');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception("Unknown task status!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$status = pht('Queued');
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Task Status'),
|
|
|
|
$status);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Task Class'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$task->getTaskClass());
|
2012-10-31 23:22:32 +01:00
|
|
|
|
|
|
|
if ($task->getLeaseExpires()) {
|
|
|
|
if ($task->getLeaseExpires() > time()) {
|
|
|
|
$lease_status = pht('Leased');
|
|
|
|
} else {
|
|
|
|
$lease_status = pht('Lease Expired');
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-29 20:01:47 +01:00
|
|
|
$lease_status = phutil_tag('em', array(), pht('Not Leased'));
|
2012-10-31 23:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Lease Status'),
|
|
|
|
$lease_status);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Lease Owner'),
|
|
|
|
$task->getLeaseOwner()
|
2013-01-29 20:01:47 +01:00
|
|
|
? $task->getLeaseOwner()
|
|
|
|
: phutil_tag('em', array(), pht('None')));
|
2012-10-31 23:22:32 +01:00
|
|
|
|
|
|
|
if ($task->getLeaseExpires() && $task->getLeaseOwner()) {
|
|
|
|
$expires = ($task->getLeaseExpires() - time());
|
|
|
|
$expires = phabricator_format_relative_time_detailed($expires);
|
|
|
|
} else {
|
2013-01-29 20:01:47 +01:00
|
|
|
$expires = phutil_tag('em', array(), pht('None'));
|
2012-10-31 23:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Lease Expires'),
|
|
|
|
$expires);
|
|
|
|
|
|
|
|
if ($task->isArchived()) {
|
2013-01-29 20:01:47 +01:00
|
|
|
$duration = number_format($task->getDuration()).' us';
|
2012-10-31 23:22:32 +01:00
|
|
|
} else {
|
2013-01-29 20:01:47 +01:00
|
|
|
$duration = phutil_tag('em', array(), pht('Not Completed'));
|
2012-10-31 23:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Duration'),
|
|
|
|
$duration);
|
|
|
|
|
2012-12-18 02:12:55 +01:00
|
|
|
$data = id(new PhabricatorWorkerTaskData())->load($task->getDataID());
|
|
|
|
$task->setData($data->getData());
|
|
|
|
$worker = $task->getWorkerInstance();
|
|
|
|
$data = $worker->renderForDisplay();
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Data'),
|
|
|
|
$data);
|
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:34:18 +02:00
|
|
|
private function buildRetryListView(PhabricatorWorkerTask $task) {
|
|
|
|
$view = new PhabricatorPropertyListView();
|
|
|
|
|
|
|
|
$data = id(new PhabricatorWorkerTaskData())->load($task->getDataID());
|
|
|
|
$task->setData($data->getData());
|
|
|
|
$worker = $task->getWorkerInstance();
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Failure Count'),
|
|
|
|
$task->getFailureCount());
|
|
|
|
|
|
|
|
$retry_count = $worker->getMaximumRetryCount();
|
|
|
|
if ($retry_count === null) {
|
|
|
|
$max_retries = phutil_tag('em', array(), pht('Retries Forever'));
|
|
|
|
$retry_count = INF;
|
|
|
|
} else {
|
|
|
|
$max_retries = $retry_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Maximum Retries'),
|
|
|
|
$max_retries);
|
|
|
|
|
|
|
|
$projection = clone $task;
|
|
|
|
$projection->makeEphemeral();
|
|
|
|
|
|
|
|
$next = array();
|
|
|
|
for ($ii = $task->getFailureCount(); $ii < $retry_count; $ii++) {
|
|
|
|
$projection->setFailureCount($ii);
|
|
|
|
$next[] = $worker->getWaitBeforeRetry($projection);
|
|
|
|
if (count($next) > 10) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($next) {
|
|
|
|
$cumulative = 0;
|
|
|
|
foreach ($next as $key => $duration) {
|
|
|
|
if ($duration === null) {
|
|
|
|
$duration = 60;
|
|
|
|
}
|
|
|
|
$cumulative += $duration;
|
|
|
|
$next[$key] = phabricator_format_relative_time($cumulative);
|
|
|
|
}
|
|
|
|
if ($ii != $retry_count) {
|
|
|
|
$next[] = '...';
|
|
|
|
}
|
|
|
|
$retries_in = implode(', ', $next);
|
|
|
|
} else {
|
|
|
|
$retries_in = pht('No More Retries');
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Retries After'),
|
|
|
|
$retries_in);
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2011-03-27 07:55:18 +02:00
|
|
|
}
|