@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.

Use events rather than Conduit to report daemon status in Phabricator

Summary: Ref T1670. Use events and direct database writes instead of Conduit. Deprecate the Conduit methods.

Test Plan: Ran daemons, used the console to review daemon event logs.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1670

Differential Revision: https://secure.phabricator.com/D6536

+125 -5
+2
src/__phutil_library_map__.php
··· 1023 1023 'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php', 1024 1024 'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php', 1025 1025 'PhabricatorDaemonDAO' => 'infrastructure/daemon/storage/PhabricatorDaemonDAO.php', 1026 + 'PhabricatorDaemonEventListener' => 'applications/daemon/event/PhabricatorDaemonEventListener.php', 1026 1027 'PhabricatorDaemonLog' => 'infrastructure/daemon/storage/PhabricatorDaemonLog.php', 1027 1028 'PhabricatorDaemonLogEvent' => 'infrastructure/daemon/storage/PhabricatorDaemonLogEvent.php', 1028 1029 'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php', ··· 3026 3027 'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController', 3027 3028 'PhabricatorDaemonController' => 'PhabricatorController', 3028 3029 'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO', 3030 + 'PhabricatorDaemonEventListener' => 'PhutilEventListener', 3029 3031 'PhabricatorDaemonLog' => 'PhabricatorDaemonDAO', 3030 3032 'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO', 3031 3033 'PhabricatorDaemonLogEventsView' => 'AphrontView',
+6
src/applications/daemon/application/PhabricatorApplicationDaemons.php
··· 30 30 return false; 31 31 } 32 32 33 + public function getEventListeners() { 34 + return array( 35 + new PhabricatorDaemonEventListener(), 36 + ); 37 + } 38 + 33 39 public function getRoutes() { 34 40 return array( 35 41 '/daemon/' => array(
+4 -1
src/applications/daemon/conduit/ConduitAPI_daemon_launched_Method.php
··· 5 5 */ 6 6 final class ConduitAPI_daemon_launched_Method extends ConduitAPIMethod { 7 7 8 + public function getMethodStatus() { 9 + return self::METHOD_STATUS_DEPRECATED; 10 + } 11 + 8 12 public function shouldRequireAuthentication() { 9 - // TODO: Lock this down once we build phantoms. 10 13 return false; 11 14 } 12 15
+4 -1
src/applications/daemon/conduit/ConduitAPI_daemon_log_Method.php
··· 5 5 */ 6 6 final class ConduitAPI_daemon_log_Method extends ConduitAPIMethod { 7 7 8 + public function getMethodStatus() { 9 + return self::METHOD_STATUS_DEPRECATED; 10 + } 11 + 8 12 public function shouldRequireAuthentication() { 9 - // TODO: Lock this down once we build phantoms. 10 13 return false; 11 14 } 12 15
+4 -1
src/applications/daemon/conduit/ConduitAPI_daemon_setstatus_Method.php
··· 5 5 */ 6 6 final class ConduitAPI_daemon_setstatus_Method extends ConduitAPIMethod { 7 7 8 + public function getMethodStatus() { 9 + return self::METHOD_STATUS_DEPRECATED; 10 + } 11 + 8 12 public function shouldRequireAuthentication() { 9 - // TODO: Lock this down once we build phantoms. 10 13 return false; 11 14 } 12 15
+104
src/applications/daemon/event/PhabricatorDaemonEventListener.php
··· 1 + <?php 2 + 3 + final class PhabricatorDaemonEventListener extends PhutilEventListener { 4 + 5 + private $daemons = array(); 6 + 7 + public function register() { 8 + $this->listen(PhutilDaemonOverseer::EVENT_DID_LAUNCH); 9 + $this->listen(PhutilDaemonOverseer::EVENT_DID_LOG); 10 + $this->listen(PhutilDaemonOverseer::EVENT_DID_HEARTBEAT); 11 + $this->listen(PhutilDaemonOverseer::EVENT_WILL_EXIT); 12 + } 13 + 14 + public function handleEvent(PhutilEvent $event) { 15 + switch ($event->getType()) { 16 + case PhutilDaemonOverseer::EVENT_DID_LAUNCH: 17 + $this->handleLaunchEvent($event); 18 + break; 19 + case PhutilDaemonOverseer::EVENT_DID_HEARTBEAT: 20 + $this->handleHeartbeatEvent($event); 21 + break; 22 + case PhutilDaemonOverseer::EVENT_DID_LOG: 23 + $this->handleLogEvent($event); 24 + break; 25 + case PhutilDaemonOverseer::EVENT_WILL_EXIT: 26 + $this->handleExitEvent($event); 27 + break; 28 + } 29 + } 30 + 31 + private function handleLaunchEvent(PhutilEvent $event) { 32 + $id = $event->getValue('id'); 33 + 34 + $daemon = id(new PhabricatorDaemonLog()) 35 + ->setDaemon($event->getValue('daemonClass')) 36 + ->setHost(php_uname('n')) 37 + ->setPID(getmypid()) 38 + ->setStatus(PhabricatorDaemonLog::STATUS_RUNNING) 39 + ->setArgv($event->getValue('argv')) 40 + ->save(); 41 + 42 + $this->daemons[$id] = $daemon; 43 + } 44 + 45 + private function handleHeartbeatEvent(PhutilEvent $event) { 46 + $daemon = $this->getDaemon($event->getValue('id')); 47 + 48 + // Just update the timestamp. 49 + $daemon->save(); 50 + } 51 + 52 + private function handleLogEvent(PhutilEvent $event) { 53 + $daemon = $this->getDaemon($event->getValue('id')); 54 + 55 + // TODO: This is a bit awkward for historical reasons, clean it up after 56 + // removing Conduit. 57 + $message = $event->getValue('message'); 58 + $context = $event->getValue('context'); 59 + if (strlen($context) && $context !== $message) { 60 + $message = "({$context}) {$message}"; 61 + } 62 + 63 + $type = $event->getValue('type'); 64 + 65 + $message = phutil_utf8ize($message); 66 + 67 + id(new PhabricatorDaemonLogEvent()) 68 + ->setLogID($daemon->getID()) 69 + ->setLogType($type) 70 + ->setMessage((string)$message) 71 + ->setEpoch(time()) 72 + ->save(); 73 + 74 + switch ($type) { 75 + case 'WAIT': 76 + $current_status = PhabricatorDaemonLog::STATUS_WAIT; 77 + break; 78 + default: 79 + $current_status = PhabricatorDaemonLog::STATUS_RUNNING; 80 + break; 81 + } 82 + 83 + if ($current_status !== $daemon->getStatus()) { 84 + $daemon->setStatus($current_status)->save(); 85 + } 86 + } 87 + 88 + private function handleExitEvent(PhutilEvent $event) { 89 + $id = $event->getValue('id'); 90 + 91 + $daemon = $this->getDaemon($id); 92 + $daemon->setStatus(PhabricatorDaemonLog::STATUS_EXITED)->save(); 93 + 94 + unset($this->daemons[$id]); 95 + } 96 + 97 + private function getDaemon($id) { 98 + if (isset($this->daemons[$id])) { 99 + return $this->daemons[$id]; 100 + } 101 + throw new Exception("No such daemon '{$id}'!"); 102 + } 103 + 104 + }
-2
src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php
··· 131 131 $flags[] = '--daemonize'; 132 132 } 133 133 134 - $flags[] = csprintf('--conduit-uri=%s', PhabricatorEnv::getURI('/api/')); 135 - 136 134 if (!$debug) { 137 135 $log_file = $this->getLogDirectory().'/daemons.log'; 138 136 $flags[] = csprintf('--log=%s', $log_file);
+1
src/infrastructure/daemon/storage/PhabricatorDaemonLog.php
··· 5 5 const STATUS_UNKNOWN = 'unknown'; 6 6 const STATUS_RUNNING = 'run'; 7 7 const STATUS_DEAD = 'dead'; 8 + const STATUS_WAIT = 'wait'; 8 9 const STATUS_EXITED = 'exit'; 9 10 10 11 protected $daemon;