@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+71 -20
+9
src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
··· 171 171 pht('Duration'), 172 172 $duration); 173 173 174 + $data = id(new PhabricatorWorkerTaskData())->load($task->getDataID()); 175 + $task->setData($data->getData()); 176 + $worker = $task->getWorkerInstance(); 177 + $data = $worker->renderForDisplay(); 178 + 179 + $view->addProperty( 180 + pht('Data'), 181 + $data); 182 + 174 183 return $view; 175 184 } 176 185
+7
src/applications/metamta/PhabricatorMetaMTAWorker.php
··· 41 41 return $this->message; 42 42 } 43 43 44 + public function renderForDisplay() { 45 + return phutil_render_tag( 46 + 'a', 47 + array('href' => '/mail/view/'.$this->getTaskData().'/'), 48 + phutil_escape_html($this->getTaskData())); 49 + } 50 + 44 51 }
+29 -6
src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php
··· 6 6 protected $commit; 7 7 protected $repository; 8 8 9 - final public function doWork() { 9 + private function loadCommit() { 10 + if ($this->commit) { 11 + return $this->commit; 12 + } 13 + 10 14 $commit_id = idx($this->getTaskData(), 'commitID'); 11 15 if (!$commit_id) { 12 - return; 16 + return false; 13 17 } 14 18 15 19 $commit = id(new PhabricatorRepositoryCommit())->load($commit_id); 16 20 17 21 if (!$commit) { 18 22 // TODO: Communicate permanent failure? 19 - return; 23 + return false; 20 24 } 21 25 22 - $this->commit = $commit; 26 + return $this->commit = $commit; 27 + } 28 + 29 + final public function doWork() { 30 + if (!$this->loadCommit()) { 31 + return; 32 + } 23 33 24 34 $repository = id(new PhabricatorRepository())->load( 25 - $commit->getRepositoryID()); 35 + $this->commit->getRepositoryID()); 26 36 27 37 if (!$repository) { 28 38 return; ··· 30 40 31 41 $this->repository = $repository; 32 42 33 - return $this->parseCommit($repository, $commit); 43 + return $this->parseCommit($repository, $this->commit); 34 44 } 35 45 36 46 final protected function shouldQueueFollowupTasks() { ··· 75 85 return (bool)$bad_commit; 76 86 } 77 87 88 + public function renderForDisplay() { 89 + $suffix = parent::renderForDisplay(); 90 + $commit = $this->loadCommit(); 91 + if (!$commit) { 92 + return $suffix; 93 + } 94 + 95 + $repository = id(new PhabricatorRepository()) 96 + ->load($commit->getRepositoryID()); 97 + $link = DiffusionView::linkCommit($repository, 98 + $commit->getCommitIdentifier()); 99 + return $link.$suffix; 100 + } 78 101 }
+7
src/infrastructure/daemon/workers/PhabricatorWorker.php
··· 149 149 } 150 150 } 151 151 152 + public function renderForDisplay() { 153 + $data = PhutilReadableSerializer::printableValue($this->data); 154 + $data = phutil_escape_html($data); 155 + $data = '<pre>'.$data.'</pre>'; 156 + return $data; 157 + } 158 + 152 159 }
+2 -14
src/infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php
··· 99 99 $this->checkLease(); 100 100 101 101 try { 102 - $id = $this->getID(); 103 - $class = $this->getTaskClass(); 104 - 105 - if (!class_exists($class)) { 106 - throw new PhabricatorWorkerPermanentFailureException( 107 - "Task class '{$class}' does not exist!"); 108 - } 109 - 110 - if (!is_subclass_of($class, 'PhabricatorWorker')) { 111 - throw new PhabricatorWorkerPermanentFailureException( 112 - "Task class '{$class}' does not extend PhabricatorWorker."); 113 - } 114 - 115 - $worker = newv($class, array($this->getData())); 102 + $worker = $this->getWorkerInstance(); 116 103 117 104 $maximum_failures = $worker->getMaximumRetryCount(); 118 105 if ($maximum_failures !== null) { 119 106 if ($this->getFailureCount() > $maximum_failures) { 107 + $id = $this->getID(); 120 108 throw new PhabricatorWorkerPermanentFailureException( 121 109 "Task {$id} has exceeded the maximum number of failures ". 122 110 "({$maximum_failures}).");
+17
src/infrastructure/daemon/workers/storage/PhabricatorWorkerTask.php
··· 35 35 return ($this instanceof PhabricatorWorkerArchiveTask); 36 36 } 37 37 38 + public function getWorkerInstance() { 39 + $id = $this->getID(); 40 + $class = $this->getTaskClass(); 41 + 42 + if (!class_exists($class)) { 43 + throw new PhabricatorWorkerPermanentFailureException( 44 + "Task class '{$class}' does not exist!"); 45 + } 46 + 47 + if (!is_subclass_of($class, 'PhabricatorWorker')) { 48 + throw new PhabricatorWorkerPermanentFailureException( 49 + "Task class '{$class}' does not extend PhabricatorWorker."); 50 + } 51 + 52 + return newv($class, array($this->getData())); 53 + } 54 + 38 55 }