mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Add "--background" and "--count" flags to "bin/webhook call"
Summary: See PHI1794, which reports an issue where a large number of queued webhook calls led to connection exhaustion. To make this easier to reproduce and test, add "--count" and "--background" flags to "bin/webhook call". This primarily supports "bin/webook call ... --background --count 10000" to quickly fill the queue with a bunch of calls. Test Plan: Ran `bin/webhook call` in foreground and background modes, with and without counts. Saw appropriate console and queue behavior. Differential Revision: https://secure.phabricator.com/D21368
This commit is contained in:
parent
9ce1271805
commit
d91abf50f7
1 changed files with 64 additions and 16 deletions
|
@ -28,6 +28,17 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
'name' => 'secure',
|
||||
'help' => pht('Set the "secure" flag on the request.'),
|
||||
),
|
||||
array(
|
||||
'name' => 'count',
|
||||
'param' => 'N',
|
||||
'help' => pht('Make a total of __N__ copies of the call.'),
|
||||
),
|
||||
array(
|
||||
'name' => 'background',
|
||||
'help' => pht(
|
||||
'Instead of making calls in the foreground, add the tasks '.
|
||||
'to the daemon queue.'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -41,6 +52,17 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
'Specify a webhook to call with "--id".'));
|
||||
}
|
||||
|
||||
$count = $args->getArg('count');
|
||||
if ($count === null) {
|
||||
$count = 1;
|
||||
}
|
||||
|
||||
if ($count <= 0) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'Specified "--count" must be larger than 0.'));
|
||||
}
|
||||
|
||||
$hook = id(new HeraldWebhookQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
|
@ -69,6 +91,8 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
$object = head($objects);
|
||||
}
|
||||
|
||||
$is_background = $args->getArg('background');
|
||||
|
||||
$xaction_query =
|
||||
PhabricatorApplicationTransactionQuery::newQueryForObject($object);
|
||||
|
||||
|
@ -80,6 +104,22 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
|
||||
$application_phid = id(new PhabricatorHeraldApplication())->getPHID();
|
||||
|
||||
if ($is_background) {
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht(
|
||||
'Queueing webhook calls...'));
|
||||
$progress_bar = id(new PhutilConsoleProgressBar())
|
||||
->setTotal($count);
|
||||
} else {
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht(
|
||||
'Calling webhook...'));
|
||||
PhabricatorWorker::setRunAllTasksInProcess(true);
|
||||
}
|
||||
|
||||
for ($ii = 0; $ii < $count; $ii++) {
|
||||
$request = HeraldWebhookRequest::initializeNewWebhookRequest($hook)
|
||||
->setObjectPHID($object->getPHID())
|
||||
->setIsTestAction(true)
|
||||
|
@ -89,9 +129,11 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
->setTransactionPHIDs(mpull($xactions, 'getPHID'))
|
||||
->save();
|
||||
|
||||
PhabricatorWorker::setRunAllTasksInProcess(true);
|
||||
$request->queueCall();
|
||||
|
||||
if ($is_background) {
|
||||
$progress_bar->update(1);
|
||||
} else {
|
||||
$request->reload();
|
||||
|
||||
echo tsprintf(
|
||||
|
@ -99,6 +141,12 @@ final class HeraldWebhookCallManagementWorkflow
|
|||
pht(
|
||||
'Success, got HTTP %s from webhook.',
|
||||
$request->getErrorCode()));
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_background) {
|
||||
$progress_bar->done();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue