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 @@ -3989,6 +3989,7 @@ 'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php', 'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php', 'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php', + 'PhabricatorTaskmasterDaemonModule' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php', 'PhabricatorTestApplication' => 'applications/base/controller/__tests__/PhabricatorTestApplication.php', 'PhabricatorTestCase' => 'infrastructure/testing/PhabricatorTestCase.php', 'PhabricatorTestController' => 'applications/base/controller/__tests__/PhabricatorTestController.php', @@ -9318,6 +9319,7 @@ 'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor', 'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase', 'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon', + 'PhabricatorTaskmasterDaemonModule' => 'PhutilDaemonOverseerModule', 'PhabricatorTestApplication' => 'PhabricatorApplication', 'PhabricatorTestCase' => 'PhutilTestCase', 'PhabricatorTestController' => 'PhabricatorController', diff --git a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php --- a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php +++ b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php @@ -43,6 +43,11 @@ $sleep = 0; } else { + + if ($this->shouldHibernate(60)) { + break; + } + // When there's no work, sleep for one second. The pool will // autoscale down if we're continuously idle for an extended period // of time. diff --git a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php new file mode 100644 --- /dev/null +++ b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemonModule.php @@ -0,0 +1,33 @@ +getPoolDaemonClass(); + + if ($class != 'PhabricatorTaskmasterDaemon') { + return false; + } + + if ($this->shouldThrottle($class, 1)) { + return false; + } + + $table = new PhabricatorWorkerActiveTask(); + $conn = $table->establishConnection('r'); + + $row = queryfx_one( + $conn, + 'SELECT id FROM %T WHERE leaseOwner IS NULL + OR leaseExpires <= %d LIMIT 1', + $table->getTableName(), + PhabricatorTime::getNow()); + if (!$row) { + return false; + } + + return true; + } + +}