mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +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:
parent
edd5c208a6
commit
4a81ae6d6d
6 changed files with 71 additions and 20 deletions
|
@ -171,6 +171,15 @@ final class PhabricatorWorkerTaskDetailController
|
||||||
pht('Duration'),
|
pht('Duration'),
|
||||||
$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;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,4 +41,11 @@ final class PhabricatorMetaMTAWorker
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderForDisplay() {
|
||||||
|
return phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array('href' => '/mail/view/'.$this->getTaskData().'/'),
|
||||||
|
phutil_escape_html($this->getTaskData()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,23 +6,33 @@ abstract class PhabricatorRepositoryCommitParserWorker
|
||||||
protected $commit;
|
protected $commit;
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
final public function doWork() {
|
private function loadCommit() {
|
||||||
|
if ($this->commit) {
|
||||||
|
return $this->commit;
|
||||||
|
}
|
||||||
|
|
||||||
$commit_id = idx($this->getTaskData(), 'commitID');
|
$commit_id = idx($this->getTaskData(), 'commitID');
|
||||||
if (!$commit_id) {
|
if (!$commit_id) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$commit = id(new PhabricatorRepositoryCommit())->load($commit_id);
|
$commit = id(new PhabricatorRepositoryCommit())->load($commit_id);
|
||||||
|
|
||||||
if (!$commit) {
|
if (!$commit) {
|
||||||
// TODO: Communicate permanent failure?
|
// TODO: Communicate permanent failure?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->commit = $commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function doWork() {
|
||||||
|
if (!$this->loadCommit()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commit = $commit;
|
|
||||||
|
|
||||||
$repository = id(new PhabricatorRepository())->load(
|
$repository = id(new PhabricatorRepository())->load(
|
||||||
$commit->getRepositoryID());
|
$this->commit->getRepositoryID());
|
||||||
|
|
||||||
if (!$repository) {
|
if (!$repository) {
|
||||||
return;
|
return;
|
||||||
|
@ -30,7 +40,7 @@ abstract class PhabricatorRepositoryCommitParserWorker
|
||||||
|
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
|
|
||||||
return $this->parseCommit($repository, $commit);
|
return $this->parseCommit($repository, $this->commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function shouldQueueFollowupTasks() {
|
final protected function shouldQueueFollowupTasks() {
|
||||||
|
@ -75,4 +85,17 @@ abstract class PhabricatorRepositoryCommitParserWorker
|
||||||
return (bool)$bad_commit;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,24 +99,12 @@ final class PhabricatorWorkerActiveTask extends PhabricatorWorkerTask {
|
||||||
$this->checkLease();
|
$this->checkLease();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$id = $this->getID();
|
$worker = $this->getWorkerInstance();
|
||||||
$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()));
|
|
||||||
|
|
||||||
$maximum_failures = $worker->getMaximumRetryCount();
|
$maximum_failures = $worker->getMaximumRetryCount();
|
||||||
if ($maximum_failures !== null) {
|
if ($maximum_failures !== null) {
|
||||||
if ($this->getFailureCount() > $maximum_failures) {
|
if ($this->getFailureCount() > $maximum_failures) {
|
||||||
|
$id = $this->getID();
|
||||||
throw new PhabricatorWorkerPermanentFailureException(
|
throw new PhabricatorWorkerPermanentFailureException(
|
||||||
"Task {$id} has exceeded the maximum number of failures ".
|
"Task {$id} has exceeded the maximum number of failures ".
|
||||||
"({$maximum_failures}).");
|
"({$maximum_failures}).");
|
||||||
|
|
|
@ -35,4 +35,21 @@ abstract class PhabricatorWorkerTask extends PhabricatorWorkerDAO {
|
||||||
return ($this instanceof PhabricatorWorkerArchiveTask);
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue