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) {
|
2014-12-24 00:45:42 +01:00
|
|
|
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->execute();
|
|
|
|
$task = reset($tasks);
|
2012-10-31 23:22:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$task) {
|
|
|
|
$title = pht('Task Does Not Exist');
|
|
|
|
|
2015-03-01 23:45:56 +01:00
|
|
|
$error_view = new PHUIInfoView();
|
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.')));
|
2015-03-01 23:45:56 +01:00
|
|
|
$error_view->setSeverity(PHUIInfoView::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
|
|
|
|
2014-12-06 18:14:16 +01:00
|
|
|
$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-12-21 03:02:32 +01:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-12-21 03:02:32 +01:00
|
|
|
$retry_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($retry_head)
|
|
|
|
->addPropertyList($retry_info);
|
2013-10-11 16:53:56 +02:00
|
|
|
|
2012-10-31 23:22:32 +01:00
|
|
|
$content = array(
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box,
|
2013-12-21 03:02:32 +01:00
|
|
|
$retry_box,
|
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();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb($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,
|
2011-03-27 07:55:18 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
private function buildPropertyListView(
|
2014-12-06 18:14:16 +01:00
|
|
|
PhabricatorWorkerTask $task) {
|
2013-10-11 16:53:56 +02:00
|
|
|
|
2013-12-21 03:02:32 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = new PHUIPropertyListView();
|
2012-10-31 23:22:32 +01:00
|
|
|
|
|
|
|
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:
|
2014-06-09 20:36:49 +02:00
|
|
|
throw new Exception('Unknown task status!');
|
2012-10-31 23:22:32 +01:00
|
|
|
}
|
|
|
|
} 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());
|
2014-07-13 04:03:17 +02:00
|
|
|
$expires = phutil_format_relative_time_detailed($expires);
|
2012-10-31 23:22:32 +01:00
|
|
|
} 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();
|
2013-12-21 03:02:32 +01:00
|
|
|
$data = $worker->renderForDisplay($viewer);
|
2012-12-18 02:12:55 +01:00
|
|
|
|
|
|
|
$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) {
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = new PHUIPropertyListView();
|
2013-07-08 23:34:18 +02:00
|
|
|
|
|
|
|
$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;
|
2014-07-13 04:03:17 +02:00
|
|
|
$next[$key] = phutil_format_relative_time($cumulative);
|
2013-07-08 23:34:18 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|