mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +01:00
Support autoscaling daemons in phd
Summary: Ref T7352. This supports passing autoscaling configuration to daemons, and adds `debug --autoscale`. Test Plan: See D11711. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7352 Differential Revision: https://secure.phabricator.com/D11860
This commit is contained in:
parent
f0f2b2cbeb
commit
48fc3126a1
4 changed files with 50 additions and 20 deletions
|
@ -26,6 +26,10 @@ final class PhabricatorDaemonManagementDebugWorkflow
|
|||
'help' => 'Run the daemon as the current user '.
|
||||
'instead of the configured phd.user',
|
||||
),
|
||||
array(
|
||||
'name' => 'autoscale',
|
||||
'help' => pht('Put the daemon in an autoscale group.'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -38,10 +42,20 @@ final class PhabricatorDaemonManagementDebugWorkflow
|
|||
pht('You must specify which daemon to debug.'));
|
||||
}
|
||||
|
||||
$daemon_class = array_shift($argv);
|
||||
$config = array();
|
||||
|
||||
$config['class'] = array_shift($argv);
|
||||
$config['argv'] = $argv;
|
||||
|
||||
if ($args->getArg('autoscale')) {
|
||||
$config['autoscale'] = array(
|
||||
'group' => 'debug',
|
||||
);
|
||||
}
|
||||
|
||||
return $this->launchDaemons(
|
||||
array(
|
||||
array($daemon_class, $argv),
|
||||
$config,
|
||||
),
|
||||
$is_debug = true,
|
||||
$run_as_current_user);
|
||||
|
|
|
@ -43,7 +43,10 @@ final class PhabricatorDaemonManagementLaunchWorkflow
|
|||
pht('You must specify which daemon to launch.'));
|
||||
}
|
||||
|
||||
$daemon = array(array_shift($argv), $argv);
|
||||
$daemon = array();
|
||||
$daemon['class'] = array_shift($argv);
|
||||
$daemon['argv'] = $argv;
|
||||
|
||||
$daemons = array_fill(0, $daemon_count, $daemon);
|
||||
|
||||
$this->launchDaemons($daemons, $is_debug = false);
|
||||
|
|
|
@ -113,8 +113,8 @@ abstract class PhabricatorDaemonManagementWorkflow
|
|||
// Convert any shorthand classnames like "taskmaster" into proper class
|
||||
// names.
|
||||
foreach ($daemons as $key => $daemon) {
|
||||
$class = $this->findDaemonClass($daemon[0]);
|
||||
$daemons[$key][0] = $class;
|
||||
$class = $this->findDaemonClass($daemon['class']);
|
||||
$daemons[$key]['class'] = $class;
|
||||
}
|
||||
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
@ -176,15 +176,7 @@ abstract class PhabricatorDaemonManagementWorkflow
|
|||
Filesystem::assertWritable($pid_dir);
|
||||
|
||||
$config['piddir'] = $pid_dir;
|
||||
|
||||
$config['daemons'] = array();
|
||||
foreach ($daemons as $daemon) {
|
||||
list($class, $argv) = $daemon;
|
||||
$config['daemons'][] = array(
|
||||
'class' => $class,
|
||||
'argv' => $argv,
|
||||
);
|
||||
}
|
||||
$config['daemons'] = $daemons;
|
||||
|
||||
$command = csprintf('./phd-daemon %Ls', $flags);
|
||||
|
||||
|
@ -327,14 +319,22 @@ abstract class PhabricatorDaemonManagementWorkflow
|
|||
}
|
||||
|
||||
$daemons = array(
|
||||
array('PhabricatorRepositoryPullLocalDaemon', array()),
|
||||
array('PhabricatorGarbageCollectorDaemon', array()),
|
||||
array('PhabricatorTriggerDaemon', array()),
|
||||
array(
|
||||
'class' => 'PhabricatorRepositoryPullLocalDaemon',
|
||||
),
|
||||
array(
|
||||
'class' => 'PhabricatorGarbageCollectorDaemon',
|
||||
),
|
||||
array(
|
||||
'class' => 'PhabricatorTriggerDaemon',
|
||||
),
|
||||
);
|
||||
|
||||
$taskmasters = PhabricatorEnv::getEnvConfig('phd.start-taskmasters');
|
||||
for ($ii = 0; $ii < $taskmasters; $ii++) {
|
||||
$daemons[] = array('PhabricatorTaskmasterDaemon', array());
|
||||
$daemons[] = array(
|
||||
'class' => 'PhabricatorTaskmasterDaemon',
|
||||
);
|
||||
}
|
||||
|
||||
$this->launchDaemons($daemons, $is_debug = false);
|
||||
|
@ -568,8 +568,18 @@ abstract class PhabricatorDaemonManagementWorkflow
|
|||
pht('(Logs will appear in "%s".)', $log_dir));
|
||||
|
||||
foreach ($daemons as $daemon) {
|
||||
list($class, $argv) = $daemon;
|
||||
$console->writeOut(" %s %s\n", $class, implode(' ', $argv));
|
||||
$is_autoscale = isset($daemon['autoscale']['group']);
|
||||
if ($is_autoscale) {
|
||||
$autoscale = pht('(Autoscaling)');
|
||||
} else {
|
||||
$autoscale = pht('(Static)');
|
||||
}
|
||||
|
||||
$console->writeOut(
|
||||
" %s %s\n",
|
||||
$daemon['class'],
|
||||
$autoscale,
|
||||
implode(' ', idx($daemon, 'argv', array())));
|
||||
}
|
||||
$console->writeOut("\n");
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
|
|||
->execute();
|
||||
|
||||
if ($tasks) {
|
||||
$this->willBeginWork();
|
||||
|
||||
foreach ($tasks as $task) {
|
||||
$id = $task->getID();
|
||||
$class = $task->getTaskClass();
|
||||
|
@ -55,6 +57,7 @@ final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
|
|||
|
||||
// The first time we sleep, we add a random offset to try to spread
|
||||
// the sleep times out somewhat evenly.
|
||||
$this->willBeginIdle();
|
||||
$sleep = $taskmaster_count + $offset;
|
||||
$offset = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue