Page MenuHomePhabricator

D17540.id42186.diff
No OneTemporary

D17540.id42186.diff

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
@@ -3692,6 +3692,7 @@
'PhabricatorRepositoryPullEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPullEventPHIDType.php',
'PhabricatorRepositoryPullEventQuery' => 'applications/repository/query/PhabricatorRepositoryPullEventQuery.php',
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
+ 'PhabricatorRepositoryPullLocalDaemonModule' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php',
'PhabricatorRepositoryPushEvent' => 'applications/repository/storage/PhabricatorRepositoryPushEvent.php',
'PhabricatorRepositoryPushEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPushEventPHIDType.php',
'PhabricatorRepositoryPushEventQuery' => 'applications/repository/query/PhabricatorRepositoryPushEventQuery.php',
@@ -8987,6 +8988,7 @@
'PhabricatorRepositoryPullEventPHIDType' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPullEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
+ 'PhabricatorRepositoryPullLocalDaemonModule' => 'PhutilDaemonOverseerModule',
'PhabricatorRepositoryPushEvent' => array(
'PhabricatorRepositoryDAO',
'PhabricatorPolicyInterface',
diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
--- a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
+++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
@@ -228,7 +228,10 @@
continue;
}
- $this->waitForUpdates($min_sleep, $retry_after);
+ $should_hibernate = $this->waitForUpdates($min_sleep, $retry_after);
+ if ($should_hibernate) {
+ break;
+ }
}
}
@@ -492,6 +495,10 @@
while (($sleep_until - time()) > 0) {
$sleep_duration = ($sleep_until - time());
+ if ($this->shouldHibernate($sleep_duration)) {
+ return true;
+ }
+
$this->log(
pht(
'Sleeping for %s more second(s)...',
@@ -501,7 +508,7 @@
if ($this->shouldExit()) {
$this->log(pht('Awakened from sleep by graceful shutdown!'));
- return;
+ return false;
}
if ($this->loadRepositoryUpdateMessages()) {
@@ -509,6 +516,8 @@
break;
}
}
+
+ return false;
}
}
diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php
@@ -0,0 +1,38 @@
+<?php
+
+final class PhabricatorRepositoryPullLocalDaemonModule
+ extends PhutilDaemonOverseerModule {
+
+ private $cursor = 0;
+
+ public function shouldWakePool(PhutilDaemonPool $pool) {
+ $class = $pool->getPoolDaemonClass();
+ if ($class != 'PhabricatorRepositoryPullLocalDaemon') {
+ return false;
+ }
+
+ if ($this->shouldThrottle($class, 1)) {
+ return false;
+ }
+
+ $table = new PhabricatorRepositoryStatusMessage();
+ $table_name = $table->getTableName();
+ $conn = $table->establishConnection('r');
+
+ $row = queryfx_one(
+ $conn,
+ 'SELECT id FROM %T WHERE statusType = %s
+ AND id > %d ORDER BY id DESC LIMIT 1',
+ $table_name,
+ PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE,
+ $this->cursor);
+
+ if (!$row) {
+ return false;
+ }
+
+ $this->cursor = (int)$row['id'];
+ return true;
+ }
+
+}
diff --git a/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php b/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
--- a/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
+++ b/src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
@@ -10,18 +10,9 @@
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) {
+ if ($this->shouldThrottle('reload', 10)) {
return false;
}
@@ -47,25 +38,17 @@
}
/**
- * Update the configuration version and timestamp.
+ * Check and update the configuration version.
*
* @return bool True if the daemons should restart, otherwise false.
*/
private function updateConfigVersion() {
- $config_version = $this->loadConfigVersion();
- $this->timestamp = PhabricatorTime::getNow();
+ $old_version = $this->configVersion;
+ $new_version = $this->loadConfigVersion();
- if (!$this->configVersion) {
- $this->configVersion = $config_version;
- return false;
- }
-
- if ($this->configVersion != $config_version) {
- $this->configVersion = $config_version;
- return true;
- }
+ $this->configVersion = $new_version;
- return false;
+ return ($old_version != $new_version);
}
}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 23, 6:08 PM (14 h, 37 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7037643
Default Alt Text
D17540.id42186.diff (5 KB)

Event Timeline