Page MenuHomePhabricator

D21368.id.diff
No OneTemporary

D21368.id.diff

diff --git a/src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php b/src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
--- a/src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
+++ b/src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
@@ -28,6 +28,17 @@
'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 @@
'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 @@
$object = head($objects);
}
+ $is_background = $args->getArg('background');
+
$xaction_query =
PhabricatorApplicationTransactionQuery::newQueryForObject($object);
@@ -80,25 +104,49 @@
$application_phid = id(new PhabricatorHeraldApplication())->getPHID();
- $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();
-
- PhabricatorWorker::setRunAllTasksInProcess(true);
- $request->queueCall();
-
- $request->reload();
-
- echo tsprintf(
- "%s\n",
- pht(
- 'Success, got HTTP %s from webhook.',
- $request->getErrorCode()));
+ 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)
+ ->setIsSilentAction((bool)$args->getArg('silent'))
+ ->setIsSecureAction((bool)$args->getArg('secure'))
+ ->setTriggerPHIDs(array($application_phid))
+ ->setTransactionPHIDs(mpull($xactions, 'getPHID'))
+ ->save();
+
+ $request->queueCall();
+
+ if ($is_background) {
+ $progress_bar->update(1);
+ } else {
+ $request->reload();
+
+ echo tsprintf(
+ "%s\n",
+ pht(
+ 'Success, got HTTP %s from webhook.',
+ $request->getErrorCode()));
+ }
+ }
+
+ if ($is_background) {
+ $progress_bar->done();
+ }
return 0;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 28, 11:24 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7707122
Default Alt Text
D21368.id.diff (3 KB)

Event Timeline