1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02: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:
epriestley 2020-06-25 17:45:48 -07:00
parent 9ce1271805
commit d91abf50f7

View file

@ -28,6 +28,17 @@ final class HeraldWebhookCallManagementWorkflow
'name' => 'secure', 'name' => 'secure',
'help' => pht('Set the "secure" flag on the request.'), '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".')); '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()) $hook = id(new HeraldWebhookQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
@ -69,6 +91,8 @@ final class HeraldWebhookCallManagementWorkflow
$object = head($objects); $object = head($objects);
} }
$is_background = $args->getArg('background');
$xaction_query = $xaction_query =
PhabricatorApplicationTransactionQuery::newQueryForObject($object); PhabricatorApplicationTransactionQuery::newQueryForObject($object);
@ -80,25 +104,49 @@ final class HeraldWebhookCallManagementWorkflow
$application_phid = id(new PhabricatorHeraldApplication())->getPHID(); $application_phid = id(new PhabricatorHeraldApplication())->getPHID();
$request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) if ($is_background) {
->setObjectPHID($object->getPHID()) echo tsprintf(
->setIsTestAction(true) "%s\n",
->setIsSilentAction((bool)$args->getArg('silent')) pht(
->setIsSecureAction((bool)$args->getArg('secure')) 'Queueing webhook calls...'));
->setTriggerPHIDs(array($application_phid)) $progress_bar = id(new PhutilConsoleProgressBar())
->setTransactionPHIDs(mpull($xactions, 'getPHID')) ->setTotal($count);
->save(); } else {
echo tsprintf(
"%s\n",
pht(
'Calling webhook...'));
PhabricatorWorker::setRunAllTasksInProcess(true);
}
PhabricatorWorker::setRunAllTasksInProcess(true); for ($ii = 0; $ii < $count; $ii++) {
$request->queueCall(); $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook)
->setObjectPHID($object->getPHID())
->setIsTestAction(true)
->setIsSilentAction((bool)$args->getArg('silent'))
->setIsSecureAction((bool)$args->getArg('secure'))
->setTriggerPHIDs(array($application_phid))
->setTransactionPHIDs(mpull($xactions, 'getPHID'))
->save();
$request->reload(); $request->queueCall();
echo tsprintf( if ($is_background) {
"%s\n", $progress_bar->update(1);
pht( } else {
'Success, got HTTP %s from webhook.', $request->reload();
$request->getErrorCode()));
echo tsprintf(
"%s\n",
pht(
'Success, got HTTP %s from webhook.',
$request->getErrorCode()));
}
}
if ($is_background) {
$progress_bar->done();
}
return 0; return 0;
} }