mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
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
This commit is contained in:
parent
3cdabb9588
commit
8b553d2f18
3 changed files with 40 additions and 0 deletions
|
@ -3989,6 +3989,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor',
|
||||
'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
|
||||
'PhabricatorTaskmasterDaemonModule' => 'PhutilDaemonOverseerModule',
|
||||
'PhabricatorTestApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorTestCase' => 'PhutilTestCase',
|
||||
'PhabricatorTestController' => 'PhabricatorController',
|
||||
|
|
|
@ -43,6 +43,11 @@ final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
|
|||
|
||||
$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.
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorTaskmasterDaemonModule
|
||||
extends PhutilDaemonOverseerModule {
|
||||
|
||||
public function shouldWakePool(PhutilDaemonPool $pool) {
|
||||
$class = $pool->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue