Skip to content

Commit 7e1c312

Browse files
author
epriestley
committed
Add bin/worker flood, for flooding the task queue with work
Summary: Ref T6615. Ref T3554. We need better tooling around the queue eventually, so start here. Test Plan: Added 100K+ tasks locally with `bin/worker flood`. Executed some of them with `bin/phd debug taskmaster` (we already have a TestWorker, used in unit tests). Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T3554, T6615 Differential Revision: https://secure.phabricator.com/D10894
1 parent 12f3f6d commit 7e1c312

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

bin/worker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_worker.php

scripts/setup/manage_worker.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$root = dirname(dirname(dirname(__FILE__)));
5+
require_once $root.'/scripts/__init_script__.php';
6+
7+
$args = new PhutilArgumentParser($argv);
8+
$args->setTagline('manage task queue');
9+
$args->setSynopsis(<<<EOSYNOPSIS
10+
**worker** __command__ [__options__]
11+
Manage the task queue.
12+
13+
EOSYNOPSIS
14+
);
15+
$args->parseStandardArguments();
16+
17+
$workflows = id(new PhutilSymbolLoader())
18+
->setAncestorClass('PhabricatorWorkerManagementWorkflow')
19+
->loadObjects();
20+
$workflows[] = new PhutilHelpArgumentWorkflow();
21+
$args->parseWorkflows($workflows);

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,8 @@
25152515
'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php',
25162516
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php',
25172517
'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php',
2518+
'PhabricatorWorkerManagementFloodWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementFloodWorkflow.php',
2519+
'PhabricatorWorkerManagementWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php',
25182520
'PhabricatorWorkerPermanentFailureException' => 'infrastructure/daemon/workers/exception/PhabricatorWorkerPermanentFailureException.php',
25192521
'PhabricatorWorkerTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerTask.php',
25202522
'PhabricatorWorkerTaskData' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerTaskData.php',
@@ -5676,6 +5678,8 @@
56765678
'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask',
56775679
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
56785680
'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery',
5681+
'PhabricatorWorkerManagementFloodWorkflow' => 'PhabricatorWorkerManagementWorkflow',
5682+
'PhabricatorWorkerManagementWorkflow' => 'PhabricatorManagementWorkflow',
56795683
'PhabricatorWorkerPermanentFailureException' => 'Exception',
56805684
'PhabricatorWorkerTask' => 'PhabricatorWorkerDAO',
56815685
'PhabricatorWorkerTaskData' => 'PhabricatorWorkerDAO',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
final class PhabricatorWorkerManagementFloodWorkflow
4+
extends PhabricatorWorkerManagementWorkflow {
5+
6+
public function didConstruct() {
7+
$this
8+
->setName('flood')
9+
->setExamples('**flood**')
10+
->setSynopsis(
11+
pht(
12+
'Flood the queue with test tasks. This command is intended for '.
13+
'use when developing and debugging Phabricator.'))
14+
->setArguments(array());
15+
}
16+
17+
public function execute(PhutilArgumentParser $args) {
18+
$console = PhutilConsole::getConsole();
19+
20+
$console->writeOut(
21+
"%s\n",
22+
pht('Adding many test tasks to worker queue. Use ^C to exit.'));
23+
24+
$n = 0;
25+
while (true) {
26+
PhabricatorWorker::scheduleTask(
27+
'PhabricatorTestWorker',
28+
array());
29+
30+
if (($n++ % 100) === 0) {
31+
$console->writeOut('.');
32+
}
33+
}
34+
}
35+
36+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
abstract class PhabricatorWorkerManagementWorkflow
4+
extends PhabricatorManagementWorkflow {}

0 commit comments

Comments
 (0)