@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+57 -25
+2
src/__phutil_library_map__.php
··· 3692 3692 'PhabricatorRepositoryPullEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPullEventPHIDType.php', 3693 3693 'PhabricatorRepositoryPullEventQuery' => 'applications/repository/query/PhabricatorRepositoryPullEventQuery.php', 3694 3694 'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', 3695 + 'PhabricatorRepositoryPullLocalDaemonModule' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php', 3695 3696 'PhabricatorRepositoryPushEvent' => 'applications/repository/storage/PhabricatorRepositoryPushEvent.php', 3696 3697 'PhabricatorRepositoryPushEventPHIDType' => 'applications/repository/phid/PhabricatorRepositoryPushEventPHIDType.php', 3697 3698 'PhabricatorRepositoryPushEventQuery' => 'applications/repository/query/PhabricatorRepositoryPushEventQuery.php', ··· 8987 8988 'PhabricatorRepositoryPullEventPHIDType' => 'PhabricatorPHIDType', 8988 8989 'PhabricatorRepositoryPullEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 8989 8990 'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', 8991 + 'PhabricatorRepositoryPullLocalDaemonModule' => 'PhutilDaemonOverseerModule', 8990 8992 'PhabricatorRepositoryPushEvent' => array( 8991 8993 'PhabricatorRepositoryDAO', 8992 8994 'PhabricatorPolicyInterface',
+11 -2
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 228 228 continue; 229 229 } 230 230 231 - $this->waitForUpdates($min_sleep, $retry_after); 231 + $should_hibernate = $this->waitForUpdates($min_sleep, $retry_after); 232 + if ($should_hibernate) { 233 + break; 234 + } 232 235 } 233 236 234 237 } ··· 492 495 while (($sleep_until - time()) > 0) { 493 496 $sleep_duration = ($sleep_until - time()); 494 497 498 + if ($this->shouldHibernate($sleep_duration)) { 499 + return true; 500 + } 501 + 495 502 $this->log( 496 503 pht( 497 504 'Sleeping for %s more second(s)...', ··· 501 508 502 509 if ($this->shouldExit()) { 503 510 $this->log(pht('Awakened from sleep by graceful shutdown!')); 504 - return; 511 + return false; 505 512 } 506 513 507 514 if ($this->loadRepositoryUpdateMessages()) { ··· 509 516 break; 510 517 } 511 518 } 519 + 520 + return false; 512 521 } 513 522 514 523 }
+38
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemonModule.php
··· 1 + <?php 2 + 3 + final class PhabricatorRepositoryPullLocalDaemonModule 4 + extends PhutilDaemonOverseerModule { 5 + 6 + private $cursor = 0; 7 + 8 + public function shouldWakePool(PhutilDaemonPool $pool) { 9 + $class = $pool->getPoolDaemonClass(); 10 + if ($class != 'PhabricatorRepositoryPullLocalDaemon') { 11 + return false; 12 + } 13 + 14 + if ($this->shouldThrottle($class, 1)) { 15 + return false; 16 + } 17 + 18 + $table = new PhabricatorRepositoryStatusMessage(); 19 + $table_name = $table->getTableName(); 20 + $conn = $table->establishConnection('r'); 21 + 22 + $row = queryfx_one( 23 + $conn, 24 + 'SELECT id FROM %T WHERE statusType = %s 25 + AND id > %d ORDER BY id DESC LIMIT 1', 26 + $table_name, 27 + PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 28 + $this->cursor); 29 + 30 + if (!$row) { 31 + return false; 32 + } 33 + 34 + $this->cursor = (int)$row['id']; 35 + return true; 36 + } 37 + 38 + }
+6 -23
src/infrastructure/daemon/overseer/PhabricatorDaemonOverseerModule.php
··· 10 10 extends PhutilDaemonOverseerModule { 11 11 12 12 private $configVersion; 13 - private $timestamp; 14 - 15 - public function __construct() { 16 - $this->timestamp = PhabricatorTime::getNow(); 17 - } 18 13 19 14 public function shouldReloadDaemons() { 20 - $now = PhabricatorTime::getNow(); 21 - $ago = ($now - $this->timestamp); 22 - 23 - // Don't check more than once every 10 seconds. 24 - if ($ago < 10) { 15 + if ($this->shouldThrottle('reload', 10)) { 25 16 return false; 26 17 } 27 18 ··· 47 38 } 48 39 49 40 /** 50 - * Update the configuration version and timestamp. 41 + * Check and update the configuration version. 51 42 * 52 43 * @return bool True if the daemons should restart, otherwise false. 53 44 */ 54 45 private function updateConfigVersion() { 55 - $config_version = $this->loadConfigVersion(); 56 - $this->timestamp = PhabricatorTime::getNow(); 57 - 58 - if (!$this->configVersion) { 59 - $this->configVersion = $config_version; 60 - return false; 61 - } 46 + $old_version = $this->configVersion; 47 + $new_version = $this->loadConfigVersion(); 62 48 63 - if ($this->configVersion != $config_version) { 64 - $this->configVersion = $config_version; 65 - return true; 66 - } 49 + $this->configVersion = $new_version; 67 50 68 - return false; 51 + return ($old_version != $new_version); 69 52 } 70 53 71 54 }