1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Add data information to daemon task view

Summary:
Load the data for daemon worker tasks when viewing them, and present
the information in a useful way. This defaults to printing the json data,
but for some classes of worker it will also link to the corresponding
object, to make debugging problems with workers easier.

Test Plan:
load /daemon/task/NNN for a CommitParserWorker and a MetaMTAWorker, and
see the addition of a data field with useful content and link.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4226
This commit is contained in:
Nick Harper 2012-12-17 17:12:55 -08:00
parent edd5c208a6
commit 4a81ae6d6d
6 changed files with 71 additions and 20 deletions

View file

@ -171,6 +171,15 @@ final class PhabricatorWorkerTaskDetailController
pht('Duration'),
$duration);
$data = id(new PhabricatorWorkerTaskData())->load($task->getDataID());
$task->setData($data->getData());
$worker = $task->getWorkerInstance();
$data = $worker->renderForDisplay();
$view->addProperty(
pht('Data'),
$data);
return $view;
}

View file

@ -41,4 +41,11 @@ final class PhabricatorMetaMTAWorker
return $this->message;
}
public function renderForDisplay() {
return phutil_render_tag(
'a',
array('href' => '/mail/view/'.$this->getTaskData().'/'),
phutil_escape_html($this->getTaskData()));
}
}

View file

@ -6,23 +6,33 @@ abstract class PhabricatorRepositoryCommitParserWorker
protected $commit;
protected $repository;
final public function doWork() {
private function loadCommit() {
if ($this->commit) {
return $this->commit;
}
$commit_id = idx($this->getTaskData(), 'commitID');
if (!$commit_id) {
return;
return false;
}
$commit = id(new PhabricatorRepositoryCommit())->load($commit_id);
if (!$commit) {
// TODO: Communicate permanent failure?
return false;
}
return $this->commit = $commit;
}
final public function doWork() {
if (!$this->loadCommit()) {
return;
}
$this->commit = $commit;
$repository = id(new PhabricatorRepository())->load(
$commit->getRepositoryID());
$this->commit->getRepositoryID());
if (!$repository) {
return;
@ -30,7 +40,7 @@ abstract class PhabricatorRepositoryCommitParserWorker
$this->repository = $repository;
return $this->parseCommit($repository, $commit);
return $this->parseCommit($repository, $this->commit);
}
final protected function shouldQueueFollowupTasks() {
@ -75,4 +85,17 @@ abstract class PhabricatorRepositoryCommitParserWorker
return (bool)$bad_commit;
}
public function renderForDisplay() {
$suffix = parent::renderForDisplay();
$commit = $this->loadCommit();
if (!$commit) {
return $suffix;
}
$repository = id(new PhabricatorRepository())
->load($commit->getRepositoryID());
$link = DiffusionView::linkCommit($repository,
$commit->getCommitIdentifier());
return $link.$suffix;
}
}

View file

@ -149,4 +149,11 @@ abstract class PhabricatorWorker {
}
}
public function renderForDisplay() {
$data = PhutilReadableSerializer::printableValue($this->data);
$data = phutil_escape_html($data);
$data = '<pre>'.$data.'</pre>';
return $data;
}
}

View file

@ -99,24 +99,12 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask {
$this->checkLease();
try {
$id = $this->getID();
$class = $this->getTaskClass();
if (!class_exists($class)) {
throw new PhabricatorWorkerPermanentFailureException(
"Task class '{$class}' does not exist!");
}
if (!is_subclass_of($class, 'PhabricatorWorker')) {
throw new PhabricatorWorkerPermanentFailureException(
"Task class '{$class}' does not extend PhabricatorWorker.");
}
$worker = newv($class, array($this->getData()));
$worker = $this->getWorkerInstance();
$maximum_failures = $worker->getMaximumRetryCount();
if ($maximum_failures !== null) {
if ($this->getFailureCount() > $maximum_failures) {
$id = $this->getID();
throw new PhabricatorWorkerPermanentFailureException(
"Task {$id} has exceeded the maximum number of failures ".
"({$maximum_failures}).");

View file

@ -35,4 +35,21 @@ abstract class PhabricatorWorkerTask extends PhabricatorWorkerDAO {
return ($this instanceof PhabricatorWorkerArchiveTask);
}
public function getWorkerInstance() {
$id = $this->getID();
$class = $this->getTaskClass();
if (!class_exists($class)) {
throw new PhabricatorWorkerPermanentFailureException(
"Task class '{$class}' does not exist!");
}
if (!is_subclass_of($class, 'PhabricatorWorker')) {
throw new PhabricatorWorkerPermanentFailureException(
"Task class '{$class}' does not extend PhabricatorWorker.");
}
return newv($class, array($this->getData()));
}
}