mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-09 05:18:29 +01:00
Allow the PullLocal daemon to hibernate, and wake it when repositories need an update
Summary: Ref T12298. This allows the PullLocal daemon to hibernate like the Trigger daemon, but automatically wakes it back up when it needs to do something. Test Plan: - Ran `bin/phd debug pulllocal --trace`. - Saw the daemon hibernate after doing a checkup on repositories. - Saw periodic queries to look for new update messages. - After clicking "Update Now" in the web UI to schedule an update, saw the daemon wake up immediately. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12298 Differential Revision: https://secure.phabricator.com/D17540
This commit is contained in:
parent
9326b4d131
commit
9099485a71
4 changed files with 57 additions and 25 deletions
|
@ -3692,6 +3692,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryPullEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPullEventPHIDType.php',
|
'PhabricatorRepositoryPullEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPullEventPHIDType.php',
|
||||||
'PhabricatorRepositoryPullEventQuery' => 'applications/repository/query/PhabricatorRepositoryPullEventQuery.php',
|
'PhabricatorRepositoryPullEventQuery' => 'applications/repository/query/PhabricatorRepositoryPullEventQuery.php',
|
||||||
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
|
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
|
||||||
|
'PhabricatorRepositoryPullLocalDaemonModule' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php',
|
||||||
'PhabricatorRepositoryPushEvent' => 'applications/repository/storage/PhabricatorRepositoryPushEvent.php',
|
'PhabricatorRepositoryPushEvent' => 'applications/repository/storage/PhabricatorRepositoryPushEvent.php',
|
||||||
'PhabricatorRepositoryPushEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPushEventPHIDType.php',
|
'PhabricatorRepositoryPushEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPushEventPHIDType.php',
|
||||||
'PhabricatorRepositoryPushEventQuery' => 'applications/repository/query/PhabricatorRepositoryPushEventQuery.php',
|
'PhabricatorRepositoryPushEventQuery' => 'applications/repository/query/PhabricatorRepositoryPushEventQuery.php',
|
||||||
|
@ -8987,6 +8988,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRepositoryPullEventPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorRepositoryPullEventPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorRepositoryPullEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorRepositoryPullEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
|
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
|
||||||
|
'PhabricatorRepositoryPullLocalDaemonModule' => 'PhutilDaemonOverseerModule',
|
||||||
'PhabricatorRepositoryPushEvent' => array(
|
'PhabricatorRepositoryPushEvent' => array(
|
||||||
'PhabricatorRepositoryDAO',
|
'PhabricatorRepositoryDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
|
|
@ -228,7 +228,10 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->waitForUpdates($min_sleep, $retry_after);
|
$should_hibernate = $this->waitForUpdates($min_sleep, $retry_after);
|
||||||
|
if ($should_hibernate) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -492,6 +495,10 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
while (($sleep_until - time()) > 0) {
|
while (($sleep_until - time()) > 0) {
|
||||||
$sleep_duration = ($sleep_until - time());
|
$sleep_duration = ($sleep_until - time());
|
||||||
|
|
||||||
|
if ($this->shouldHibernate($sleep_duration)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->log(
|
$this->log(
|
||||||
pht(
|
pht(
|
||||||
'Sleeping for %s more second(s)...',
|
'Sleeping for %s more second(s)...',
|
||||||
|
@ -501,7 +508,7 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
|
|
||||||
if ($this->shouldExit()) {
|
if ($this->shouldExit()) {
|
||||||
$this->log(pht('Awakened from sleep by graceful shutdown!'));
|
$this->log(pht('Awakened from sleep by graceful shutdown!'));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->loadRepositoryUpdateMessages()) {
|
if ($this->loadRepositoryUpdateMessages()) {
|
||||||
|
@ -509,6 +516,8 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,18 +10,9 @@ final class PhabricatorDaemonOverseerModule
|
||||||
extends PhutilDaemonOverseerModule {
|
extends PhutilDaemonOverseerModule {
|
||||||
|
|
||||||
private $configVersion;
|
private $configVersion;
|
||||||
private $timestamp;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->timestamp = PhabricatorTime::getNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function shouldReloadDaemons() {
|
public function shouldReloadDaemons() {
|
||||||
$now = PhabricatorTime::getNow();
|
if ($this->shouldThrottle('reload', 10)) {
|
||||||
$ago = ($now - $this->timestamp);
|
|
||||||
|
|
||||||
// Don't check more than once every 10 seconds.
|
|
||||||
if ($ago < 10) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,25 +38,17 @@ final class PhabricatorDaemonOverseerModule
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the configuration version and timestamp.
|
* Check and update the configuration version.
|
||||||
*
|
*
|
||||||
* @return bool True if the daemons should restart, otherwise false.
|
* @return bool True if the daemons should restart, otherwise false.
|
||||||
*/
|
*/
|
||||||
private function updateConfigVersion() {
|
private function updateConfigVersion() {
|
||||||
$config_version = $this->loadConfigVersion();
|
$old_version = $this->configVersion;
|
||||||
$this->timestamp = PhabricatorTime::getNow();
|
$new_version = $this->loadConfigVersion();
|
||||||
|
|
||||||
if (!$this->configVersion) {
|
$this->configVersion = $new_version;
|
||||||
$this->configVersion = $config_version;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->configVersion != $config_version) {
|
return ($old_version != $new_version);
|
||||||
$this->configVersion = $config_version;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue