@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 a daemon overseer module to restart daemons when config changes

Summary: Fixes T7053. Depends on D14452.

Test Plan:
Created a custom daemon which dumps out the config hash (by querying `PhabricatorEnv::calculateEnvironmentHash()`). Ran this daemon with `./bin/phd debug PhabricatorDebugDaemon` and saw the config hash update within 30 seconds.

{P1886}

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T7053

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

+69
+2
src/__phutil_library_map__.php
··· 2014 2014 'PhabricatorDaemonManagementStatusWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php', 2015 2015 'PhabricatorDaemonManagementStopWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStopWorkflow.php', 2016 2016 'PhabricatorDaemonManagementWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementWorkflow.php', 2017 + 'PhabricatorDaemonOverseerModule' => 'infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php', 2017 2018 'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php', 2018 2019 'PhabricatorDaemonTaskGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php', 2019 2020 'PhabricatorDaemonTasksTableView' => 'applications/daemon/view/PhabricatorDaemonTasksTableView.php', ··· 6076 6077 'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow', 6077 6078 'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow', 6078 6079 'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow', 6080 + 'PhabricatorDaemonOverseerModule' => 'PhutilDaemonOverseerModule', 6079 6081 'PhabricatorDaemonReference' => 'Phobject', 6080 6082 'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector', 6081 6083 'PhabricatorDaemonTasksTableView' => 'AphrontView',
+67
src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
··· 1 + <?php 2 + 3 + /** 4 + * Overseer module. 5 + * 6 + * The primary purpose of this overseer module is to poll for configuration 7 + * changes and reload daemons when the configuration changes. 8 + */ 9 + final class PhabricatorDaemonOverseerModule 10 + extends PhutilDaemonOverseerModule { 11 + 12 + private $configVersion; 13 + private $timestamp; 14 + 15 + public function __construct() { 16 + $this->timestamp = PhabricatorTime::getNow(); 17 + } 18 + 19 + public function shouldReloadDaemons() { 20 + if ($this->timestamp < PhabricatorTime::getNow() - 10) { 21 + return false; 22 + } 23 + 24 + return $this->updateConfigVersion(); 25 + } 26 + 27 + /** 28 + * Calculate a version number for the current Phabricator configuration. 29 + * 30 + * The version number has no real meaning and does not provide any real 31 + * indication of whether a configuration entry has been changed. The config 32 + * version is intended to be a rough indicator that "something has changed", 33 + * which indicates to the overseer that the daemons should be reloaded. 34 + * 35 + * @return int 36 + */ 37 + private function loadConfigVersion() { 38 + $conn_r = id(new PhabricatorConfigEntry())->establishConnection('r'); 39 + return head(queryfx_one( 40 + $conn_r, 41 + 'SELECT MAX(id) FROM %T', 42 + id(new PhabricatorConfigTransaction())->getTableName())); 43 + } 44 + 45 + /** 46 + * Update the configuration version and timestamp. 47 + * 48 + * @return bool True if the daemons should restart, otherwise false. 49 + */ 50 + private function updateConfigVersion() { 51 + $config_version = $this->loadConfigVersion(); 52 + $this->timestamp = PhabricatorTime::getNow(); 53 + 54 + if (!$this->configVersion) { 55 + $this->configVersion = $config_version; 56 + return false; 57 + } 58 + 59 + if ($this->configVersion != $config_version) { 60 + $this->configVersion = $config_version; 61 + return true; 62 + } 63 + 64 + return false; 65 + } 66 + 67 + }