Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15437407
D14458.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14458.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2014,6 +2014,7 @@
'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 @@
'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow',
'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow',
'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow',
+ 'PhabricatorDaemonOverseerModule' => 'PhutilDaemonOverseerModule',
'PhabricatorDaemonReference' => 'Phobject',
'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector',
'PhabricatorDaemonTasksTableView' => 'AphrontView',
diff --git a/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php b/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
@@ -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;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 26, 7:16 PM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7579823
Default Alt Text
D14458.id.diff (3 KB)
Attached To
Mode
D14458: Add a daemon overseer module to restart daemons when config changes
Attached
Detach File
Event Timeline
Log In to Comment