From 4402f372dc15cbf9565b6d26eb56ccfb050ced3b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 3 Oct 2023 14:21:16 -0700 Subject: [PATCH] Rename Queue::runLoop() to Queue::run() --- Civi/Api4/Action/Queue/{RunLoop.php => Run.php} | 2 +- Civi/Api4/Queue.php | 14 +++++++------- tests/phpunit/api/v4/Entity/QueueTest.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) rename Civi/Api4/Action/Queue/{RunLoop.php => Run.php} (98%) diff --git a/Civi/Api4/Action/Queue/RunLoop.php b/Civi/Api4/Action/Queue/Run.php similarity index 98% rename from Civi/Api4/Action/Queue/RunLoop.php rename to Civi/Api4/Action/Queue/Run.php index 4d1a61a273..80e230e26f 100644 --- a/Civi/Api4/Action/Queue/RunLoop.php +++ b/Civi/Api4/Action/Queue/Run.php @@ -31,7 +31,7 @@ use Civi\Api4\Queue; * @method ?int getMaxDuration() * @method $this setMaxDuration(?int $maxDuration) */ -class RunLoop extends \Civi\Api4\Generic\AbstractAction { +class Run extends \Civi\Api4\Generic\AbstractAction { /** * Name of the target queue. diff --git a/Civi/Api4/Queue.php b/Civi/Api4/Queue.php index ef468032e9..9a8bc353d3 100644 --- a/Civi/Api4/Queue.php +++ b/Civi/Api4/Queue.php @@ -12,7 +12,7 @@ namespace Civi\Api4; use Civi\Api4\Action\Queue\ClaimItems; use Civi\Api4\Action\Queue\RunItems; -use Civi\Api4\Action\Queue\RunLoop; +use Civi\Api4\Action\Queue\Run; /** * Track a list of durable/scannable queues. @@ -69,15 +69,15 @@ class Queue extends \Civi\Api4\Generic\DAOEntity { /** * Run a series of items from a queue. * - * Note: This is appropriate for persistent, auto-run queues. - * - * Note: `runLoop()` executes several units-of-work. It may handle multiple batches. + * This is a lightweight main-loop for development/testing. It may have some limited utility for + * sysadmins who want to fine-tune runners on a specific queue. See the class docblock for + * more information. * * @param bool $checkPermissions - * @return \Civi\Api4\Action\Queue\RunLoop + * @return \Civi\Api4\Action\Queue\Run */ - public static function runLoop($checkPermissions = TRUE) { - return (new RunLoop(static::getEntityName(), __FUNCTION__)) + public static function run($checkPermissions = TRUE) { + return (new Run(static::getEntityName(), __FUNCTION__)) ->setCheckPermissions($checkPermissions); } diff --git a/tests/phpunit/api/v4/Entity/QueueTest.php b/tests/phpunit/api/v4/Entity/QueueTest.php index 5da25ca24d..c807b9a407 100644 --- a/tests/phpunit/api/v4/Entity/QueueTest.php +++ b/tests/phpunit/api/v4/Entity/QueueTest.php @@ -187,7 +187,7 @@ class QueueTest extends Api4TestBase { } // 20 items ==> 4 per batch ==> 5 batches. Let's run the first 3... - $result = Queue::runLoop(0)->setQueue($queueName)->setMaxRequests(3)->execute(); + $result = Queue::run(0)->setQueue($queueName)->setMaxRequests(3)->execute(); $this->assertEquals([0, 1, 2, 3], \Civi::$statics[__CLASS__]['onHookQueueRunLog'][0], 'Scope of first batch'); $this->assertEquals([4, 5, 6, 7], \Civi::$statics[__CLASS__]['onHookQueueRunLog'][1], 'Scope of second batch'); $this->assertEquals([8, 9, 10, 11], \Civi::$statics[__CLASS__]['onHookQueueRunLog'][2], 'Scope of third batch'); @@ -201,7 +201,7 @@ class QueueTest extends Api4TestBase { $this->assertEquals(8, $result[0]['queue_total'], 'Due to request limit, we left some items in queue'); // And run any remaining batches... - $result = Queue::runLoop(0)->setQueue($queueName)->setMaxRequests(10)->execute(); + $result = Queue::run(0)->setQueue($queueName)->setMaxRequests(10)->execute(); $this->assertEquals([12, 13, 14, 15], \Civi::$statics[__CLASS__]['onHookQueueRunLog'][3], 'Scope of fourth batch'); $this->assertEquals([16, 17, 18, 19], \Civi::$statics[__CLASS__]['onHookQueueRunLog'][4], 'Scope of fifth batch'); $this->assertEquals(8, $result[0]['item_successes']); @@ -230,7 +230,7 @@ class QueueTest extends Api4TestBase { \Civi::queue($queueName)->createItem(new \CRM_Queue_Task([__CLASS__, 'dummyTask'], ['ok'])); /*E*/ // 20 items ==> 4 per batch ==> 5 batches. Let's run the first 3... - $result = Queue::runLoop(0)->setQueue($queueName)->execute(); + $result = Queue::run(0)->setQueue($queueName)->execute(); $this->assertEquals(3, $result[0]['item_successes'], "Executed A+B+C"); $this->assertEquals(1, $result[0]['item_errors'], "Exception on D"); $this->assertEquals(4, $result[0]['loop_requests'], "Attempted A+B+C+D"); -- 2.25.1