Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
6.2 kB · 234 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235<?php
final class PhabricatorWorkerTaskDetailController extends PhabricatorDaemonController {
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id');
$task = id(new PhabricatorWorkerActiveTask())->load($id); if (!$task) { $tasks = id(new PhabricatorWorkerArchiveTaskQuery()) ->withIDs(array($id)) ->execute(); $task = reset($tasks); }
$header = new PHUIHeaderView();
if (!$task) { $title = pht('Task Does Not Exist');
$header->setHeader(pht('Task %d Missing', $id));
$error_view = new PHUIInfoView(); $error_view->setTitle(pht('No Such Task')); $error_view->appendChild(phutil_tag( 'p', array(), pht('This task may have recently been garbage collected.'))); $error_view->setSeverity(PHUIInfoView::SEVERITY_NODATA);
$content = $error_view; } else { $title = pht('Task %d', $task->getID());
$header->setHeader( pht( 'Task %d: %s', $task->getID(), $task->getTaskClass()));
$properties = $this->buildPropertyListView($task);
$object_box = id(new PHUIObjectBoxView()) ->setHeaderText($title) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->addPropertyList($properties);
$retry_head = id(new PHUIHeaderView()) ->setHeader(pht('Retries'));
$retry_info = $this->buildRetryListView($task);
$retry_box = id(new PHUIObjectBoxView()) ->setHeader($retry_head) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->addPropertyList($retry_info);
$content = array( $object_box, $retry_box, ); }
$header->setHeaderIcon('fa-sort');
$crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $crumbs->setBorder(true);
$view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter($content);
return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); }
private function buildPropertyListView(PhabricatorWorkerTask $task) { $viewer = $this->getViewer();
$view = new PHUIPropertyListView();
$object_phid = $task->getObjectPHID(); if ($object_phid) { $handles = $viewer->loadHandles(array($object_phid)); $handle = $handles[$object_phid]; if ($handle->isComplete()) { $view->addProperty(pht('Object'), $handle->renderLink()); } }
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(pht('Unknown task status!')); } } else { $status = pht('Queued'); }
$view->addProperty( pht('Task Status'), $status);
$view->addProperty( pht('Task Class'), $task->getTaskClass());
if ($task->getLeaseExpires()) { if ($task->getLeaseExpires() > time()) { $lease_status = pht('Leased'); } else { $lease_status = pht('Lease Expired'); } } else { $lease_status = phutil_tag('em', array(), pht('Not Leased')); }
$view->addProperty( pht('Lease Status'), $lease_status);
$view->addProperty( pht('Lease Owner'), $task->getLeaseOwner() ? $task->getLeaseOwner() : phutil_tag('em', array(), pht('None')));
if ($task->getLeaseExpires() && $task->getLeaseOwner()) { $expires = ($task->getLeaseExpires() - time()); $expires = phutil_format_relative_time_detailed($expires); } else { $expires = phutil_tag('em', array(), pht('None')); }
$view->addProperty( pht('Lease Expires'), $expires);
if ($task->isArchived()) { $duration = pht('%s us', new PhutilNumber($task->getDuration())); } else { $duration = phutil_tag('em', array(), pht('Not Completed')); }
$view->addProperty( pht('Duration'), $duration);
$data = id(new PhabricatorWorkerTaskData())->load($task->getDataID()); $task->setData($data->getData()); $worker = $task->getWorkerInstance(); $data = $worker->renderForDisplay($viewer);
if ($data !== null) { $view->addProperty(pht('Data'), $data); }
return $view; }
private function buildRetryListView(PhabricatorWorkerTask $task) { $view = new PHUIPropertyListView();
$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] = phutil_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; }
}