forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorDaemonOverseerModule.php
71 lines (59 loc) · 1.84 KB
/
PhabricatorDaemonOverseerModule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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() {
$now = PhabricatorTime::getNow();
$ago = ($now - $this->timestamp);
// Don't check more than once every 10 seconds.
if ($ago < 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;
}
}