1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-07 20:38:32 +01:00

(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
This commit is contained in:
epriestley 2017-02-28 07:13:35 -08:00
parent c8f5fb1205
commit 216f6be11e
3 changed files with 31 additions and 3 deletions

View file

@ -21,6 +21,12 @@ final class PhabricatorDaemonManagementDebugWorkflow
'name' => 'argv', 'name' => 'argv',
'wildcard' => true, 'wildcard' => true,
), ),
array(
'name' => 'pool',
'param' => 'count',
'help' => pht('Maximum pool size.'),
'default' => 1,
),
array( array(
'name' => 'as-current-user', 'name' => 'as-current-user',
'help' => pht( 'help' => pht(
@ -43,6 +49,7 @@ final class PhabricatorDaemonManagementDebugWorkflow
$config = array( $config = array(
'class' => array_shift($argv), 'class' => array_shift($argv),
'label' => 'debug', 'label' => 'debug',
'pool' => (int)$args->getArg('pool'),
'argv' => $argv, 'argv' => $argv,
); );

View file

@ -24,7 +24,14 @@ final class PhabricatorTestWorker extends PhabricatorWorker {
} }
protected function doWork() { 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': case 'fail-temporary':
throw new Exception(pht('Temporary failure!')); throw new Exception(pht('Temporary failure!'));
case 'fail-permanent': case 'fail-permanent':

View file

@ -11,12 +11,24 @@ final class PhabricatorWorkerManagementFloodWorkflow
pht( pht(
'Flood the queue with test tasks. This command is intended for '. 'Flood the queue with test tasks. This command is intended for '.
'use when developing and debugging Phabricator.')) '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) { public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$duration = (float)$args->getArg('duration');
$console->writeOut( $console->writeOut(
"%s\n", "%s\n",
pht('Adding many test tasks to worker queue. Use ^C to exit.')); pht('Adding many test tasks to worker queue. Use ^C to exit.'));
@ -25,7 +37,9 @@ final class PhabricatorWorkerManagementFloodWorkflow
while (true) { while (true) {
PhabricatorWorker::scheduleTask( PhabricatorWorker::scheduleTask(
'PhabricatorTestWorker', 'PhabricatorTestWorker',
array()); array(
'duration' => $duration,
));
if (($n++ % 100) === 0) { if (($n++ % 100) === 0) {
$console->writeOut('.'); $console->writeOut('.');