diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php index f302a1e8a0..23d5a54eeb 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php @@ -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); diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php index 7ca32a2567..a3cb3fd47e 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php @@ -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); diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php index e108ddfc16..24cd531515 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementWorkflow.php @@ -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"); } diff --git a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php index d95c7d9f10..f48194bb36 100644 --- a/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php +++ b/src/infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php @@ -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; }