From 216f6be11ece53cb1daafc8fff636dbdb0d7ef3d Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 28 Feb 2017 07:13:35 -0800 Subject: [PATCH] (stable) Add "--pool" and "--duration" flags to daemon CLI tools Summary: Ref T12331. These changes are intended to make it easier to debug T12331 since I'm having difficulty reproducing the issue locally. Test Plan: - Ran `bin/phd debug task --pool 4` and got an autoscaling pool. - Ran `bin/worker flood --duration 3` and got some 3-second-long tasks to execute with `bin/worker execute ...`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12331 Differential Revision: https://secure.phabricator.com/D17431 --- ...habricatorDaemonManagementDebugWorkflow.php | 7 +++++++ .../__tests__/PhabricatorTestWorker.php | 9 ++++++++- ...habricatorWorkerManagementFloodWorkflow.php | 18 ++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php index 9a535af617..e861d238f2 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php @@ -21,6 +21,12 @@ final class PhabricatorDaemonManagementDebugWorkflow 'name' => 'argv', 'wildcard' => true, ), + array( + 'name' => 'pool', + 'param' => 'count', + 'help' => pht('Maximum pool size.'), + 'default' => 1, + ), array( 'name' => 'as-current-user', 'help' => pht( @@ -43,6 +49,7 @@ final class PhabricatorDaemonManagementDebugWorkflow $config = array( 'class' => array_shift($argv), 'label' => 'debug', + 'pool' => (int)$args->getArg('pool'), 'argv' => $argv, ); diff --git a/src/infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php b/src/infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php index 86e83acb82..f899ec1775 100644 --- a/src/infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php +++ b/src/infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php @@ -24,7 +24,14 @@ final class PhabricatorTestWorker extends PhabricatorWorker { } protected function doWork() { - switch (idx($this->getTaskData(), 'doWork')) { + $data = $this->getTaskData(); + + $duration = idx($data, 'duration'); + if ($duration) { + usleep($duration * 1000000); + } + + switch (idx($data, 'doWork')) { case 'fail-temporary': throw new Exception(pht('Temporary failure!')); case 'fail-permanent': diff --git a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFloodWorkflow.php b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFloodWorkflow.php index 9bf52cfb71..fb067ddaac 100644 --- a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFloodWorkflow.php +++ b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementFloodWorkflow.php @@ -11,12 +11,24 @@ final class PhabricatorWorkerManagementFloodWorkflow pht( 'Flood the queue with test tasks. This command is intended for '. 'use when developing and debugging Phabricator.')) - ->setArguments(array()); + ->setArguments( + array( + array( + 'name' => 'duration', + 'param' => 'seconds', + 'help' => pht( + 'Queue tasks which require a specific amount of wall time to '. + 'complete. By default, tasks complete as quickly as possible.'), + 'default' => 0, + ), + )); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); + $duration = (float)$args->getArg('duration'); + $console->writeOut( "%s\n", pht('Adding many test tasks to worker queue. Use ^C to exit.')); @@ -25,7 +37,9 @@ final class PhabricatorWorkerManagementFloodWorkflow while (true) { PhabricatorWorker::scheduleTask( 'PhabricatorTestWorker', - array()); + array( + 'duration' => $duration, + )); if (($n++ % 100) === 0) { $console->writeOut('.');