@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+64 -16
+64 -16
src/applications/herald/management/HeraldWebhookCallManagementWorkflow.php
··· 28 28 'name' => 'secure', 29 29 'help' => pht('Set the "secure" flag on the request.'), 30 30 ), 31 + array( 32 + 'name' => 'count', 33 + 'param' => 'N', 34 + 'help' => pht('Make a total of __N__ copies of the call.'), 35 + ), 36 + array( 37 + 'name' => 'background', 38 + 'help' => pht( 39 + 'Instead of making calls in the foreground, add the tasks '. 40 + 'to the daemon queue.'), 41 + ), 31 42 )); 32 43 } 33 44 ··· 41 52 'Specify a webhook to call with "--id".')); 42 53 } 43 54 55 + $count = $args->getArg('count'); 56 + if ($count === null) { 57 + $count = 1; 58 + } 59 + 60 + if ($count <= 0) { 61 + throw new PhutilArgumentUsageException( 62 + pht( 63 + 'Specified "--count" must be larger than 0.')); 64 + } 65 + 44 66 $hook = id(new HeraldWebhookQuery()) 45 67 ->setViewer($viewer) 46 68 ->withIDs(array($id)) ··· 69 91 $object = head($objects); 70 92 } 71 93 94 + $is_background = $args->getArg('background'); 95 + 72 96 $xaction_query = 73 97 PhabricatorApplicationTransactionQuery::newQueryForObject($object); 74 98 ··· 80 104 81 105 $application_phid = id(new PhabricatorHeraldApplication())->getPHID(); 82 106 83 - $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) 84 - ->setObjectPHID($object->getPHID()) 85 - ->setIsTestAction(true) 86 - ->setIsSilentAction((bool)$args->getArg('silent')) 87 - ->setIsSecureAction((bool)$args->getArg('secure')) 88 - ->setTriggerPHIDs(array($application_phid)) 89 - ->setTransactionPHIDs(mpull($xactions, 'getPHID')) 90 - ->save(); 107 + if ($is_background) { 108 + echo tsprintf( 109 + "%s\n", 110 + pht( 111 + 'Queueing webhook calls...')); 112 + $progress_bar = id(new PhutilConsoleProgressBar()) 113 + ->setTotal($count); 114 + } else { 115 + echo tsprintf( 116 + "%s\n", 117 + pht( 118 + 'Calling webhook...')); 119 + PhabricatorWorker::setRunAllTasksInProcess(true); 120 + } 91 121 92 - PhabricatorWorker::setRunAllTasksInProcess(true); 93 - $request->queueCall(); 122 + for ($ii = 0; $ii < $count; $ii++) { 123 + $request = HeraldWebhookRequest::initializeNewWebhookRequest($hook) 124 + ->setObjectPHID($object->getPHID()) 125 + ->setIsTestAction(true) 126 + ->setIsSilentAction((bool)$args->getArg('silent')) 127 + ->setIsSecureAction((bool)$args->getArg('secure')) 128 + ->setTriggerPHIDs(array($application_phid)) 129 + ->setTransactionPHIDs(mpull($xactions, 'getPHID')) 130 + ->save(); 94 131 95 - $request->reload(); 132 + $request->queueCall(); 96 133 97 - echo tsprintf( 98 - "%s\n", 99 - pht( 100 - 'Success, got HTTP %s from webhook.', 101 - $request->getErrorCode())); 134 + if ($is_background) { 135 + $progress_bar->update(1); 136 + } else { 137 + $request->reload(); 138 + 139 + echo tsprintf( 140 + "%s\n", 141 + pht( 142 + 'Success, got HTTP %s from webhook.', 143 + $request->getErrorCode())); 144 + } 145 + } 146 + 147 + if ($is_background) { 148 + $progress_bar->done(); 149 + } 102 150 103 151 return 0; 104 152 }