@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 taskmaster daemons to hibernate

Summary: Ref T12298. Like PullLocal daemons, this allows the last daemon in the pool to hibernate if there's no work to be done, and awakens the pool when work arrives.

Test Plan:
- Ran `bin/phd debug task --trace`.
- Saw the pool hibernate and look for tasks.
- Commented on an object.
- Saw the pool wake up and process the queue.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12298

Differential Revision: https://secure.phabricator.com/D17559

+40
+2
src/__phutil_library_map__.php
··· 3989 3989 'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php', 3990 3990 'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php', 3991 3991 'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php', 3992 + 'PhabricatorTaskmasterDaemonModule' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php', 3992 3993 'PhabricatorTestApplication' => 'applications/base/controller/__tests__/PhabricatorTestApplication.php', 3993 3994 'PhabricatorTestCase' => 'infrastructure/testing/PhabricatorTestCase.php', 3994 3995 'PhabricatorTestController' => 'applications/base/controller/__tests__/PhabricatorTestController.php', ··· 9318 9319 'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor', 9319 9320 'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase', 9320 9321 'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon', 9322 + 'PhabricatorTaskmasterDaemonModule' => 'PhutilDaemonOverseerModule', 9321 9323 'PhabricatorTestApplication' => 'PhabricatorApplication', 9322 9324 'PhabricatorTestCase' => 'PhutilTestCase', 9323 9325 'PhabricatorTestController' => 'PhabricatorController',
+5
src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php
··· 43 43 44 44 $sleep = 0; 45 45 } else { 46 + 47 + if ($this->shouldHibernate(60)) { 48 + break; 49 + } 50 + 46 51 // When there's no work, sleep for one second. The pool will 47 52 // autoscale down if we're continuously idle for an extended period 48 53 // of time.
+33
src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php
··· 1 + <?php 2 + 3 + final class PhabricatorTaskmasterDaemonModule 4 + extends PhutilDaemonOverseerModule { 5 + 6 + public function shouldWakePool(PhutilDaemonPool $pool) { 7 + $class = $pool->getPoolDaemonClass(); 8 + 9 + if ($class != 'PhabricatorTaskmasterDaemon') { 10 + return false; 11 + } 12 + 13 + if ($this->shouldThrottle($class, 1)) { 14 + return false; 15 + } 16 + 17 + $table = new PhabricatorWorkerActiveTask(); 18 + $conn = $table->establishConnection('r'); 19 + 20 + $row = queryfx_one( 21 + $conn, 22 + 'SELECT id FROM %T WHERE leaseOwner IS NULL 23 + OR leaseExpires <= %d LIMIT 1', 24 + $table->getTableName(), 25 + PhabricatorTime::getNow()); 26 + if (!$row) { 27 + return false; 28 + } 29 + 30 + return true; 31 + } 32 + 33 + }