mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
9f2fc7f938
commit
a07a8aca24
2 changed files with 69 additions and 0 deletions
|
@ -2014,6 +2014,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementStatusWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php',
|
||||
'PhabricatorDaemonManagementStopWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStopWorkflow.php',
|
||||
'PhabricatorDaemonManagementWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementWorkflow.php',
|
||||
'PhabricatorDaemonOverseerModule' => 'infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php',
|
||||
'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php',
|
||||
'PhabricatorDaemonTaskGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php',
|
||||
'PhabricatorDaemonTasksTableView' => 'applications/daemon/view/PhabricatorDaemonTasksTableView.php',
|
||||
|
@ -6076,6 +6077,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorDaemonOverseerModule' => 'PhutilDaemonOverseerModule',
|
||||
'PhabricatorDaemonReference' => 'Phobject',
|
||||
'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'PhabricatorDaemonTasksTableView' => 'AphrontView',
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Overseer module.
|
||||
*
|
||||
* The primary purpose of this overseer module is to poll for configuration
|
||||
* changes and reload daemons when the configuration changes.
|
||||
*/
|
||||
final class PhabricatorDaemonOverseerModule
|
||||
extends PhutilDaemonOverseerModule {
|
||||
|
||||
private $configVersion;
|
||||
private $timestamp;
|
||||
|
||||
public function __construct() {
|
||||
$this->timestamp = PhabricatorTime::getNow();
|
||||
}
|
||||
|
||||
public function shouldReloadDaemons() {
|
||||
if ($this->timestamp < PhabricatorTime::getNow() - 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->updateConfigVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a version number for the current Phabricator configuration.
|
||||
*
|
||||
* The version number has no real meaning and does not provide any real
|
||||
* indication of whether a configuration entry has been changed. The config
|
||||
* version is intended to be a rough indicator that "something has changed",
|
||||
* which indicates to the overseer that the daemons should be reloaded.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function loadConfigVersion() {
|
||||
$conn_r = id(new PhabricatorConfigEntry())->establishConnection('r');
|
||||
return head(queryfx_one(
|
||||
$conn_r,
|
||||
'SELECT MAX(id) FROM %T',
|
||||
id(new PhabricatorConfigTransaction())->getTableName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the configuration version and timestamp.
|
||||
*
|
||||
* @return bool True if the daemons should restart, otherwise false.
|
||||
*/
|
||||
private function updateConfigVersion() {
|
||||
$config_version = $this->loadConfigVersion();
|
||||
$this->timestamp = PhabricatorTime::getNow();
|
||||
|
||||
if (!$this->configVersion) {
|
||||
$this->configVersion = $config_version;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->configVersion != $config_version) {
|
||||
$this->configVersion = $config_version;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue