From 84f47dc1d218e234f3f55f6dad7ca4a6d91af71e Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 28 Feb 2024 20:21:35 +0200 Subject: [PATCH 1/4] adding limit to queue retry --- src/Appwrite/Platform/Tasks/QueueRetry.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/QueueRetry.php b/src/Appwrite/Platform/Tasks/QueueRetry.php index cba68f9936..bae5a59c45 100644 --- a/src/Appwrite/Platform/Tasks/QueueRetry.php +++ b/src/Appwrite/Platform/Tasks/QueueRetry.php @@ -7,6 +7,7 @@ use Utopia\CLI\Console; use Utopia\Platform\Action; use Utopia\Queue\Client; use Utopia\Queue\Connection; +use Utopia\Validator\Integer; use Utopia\Validator\WhiteList; class QueueRetry extends Action @@ -35,15 +36,17 @@ class QueueRetry extends Action Event::MIGRATIONS_QUEUE_NAME, Event::HAMSTER_CLASS_NAME ]), 'Queue name') + ->param('limit', 0, new Integer(true), 'jobs limit', true) ->inject('queue') - ->callback(fn ($name, $queue) => $this->action($name, $queue)); + ->callback(fn ($name, $limit, $queue) => $this->action($name, $limit, $queue)); } /** * @param string $name The name of the queue to retry jobs from + * @param int $limit * @param Connection $queue */ - public function action(string $name, Connection $queue): void + public function action(string $name, int $limit, Connection $queue): void { if (!$name) { Console::error('Missing required parameter $name'); @@ -59,6 +62,6 @@ class QueueRetry extends Action Console::log('Retrying failed jobs...'); - $queueClient->retry(); + $queueClient->retry($limit); } } From 53438acccebe3f0fd8d699f20051ac5e81f09a99 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 28 Feb 2024 21:01:42 +0200 Subject: [PATCH 2/4] adding limit to queue retry --- src/Appwrite/Platform/Tasks/QueueRetry.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/QueueRetry.php b/src/Appwrite/Platform/Tasks/QueueRetry.php index bae5a59c45..6c7714ff04 100644 --- a/src/Appwrite/Platform/Tasks/QueueRetry.php +++ b/src/Appwrite/Platform/Tasks/QueueRetry.php @@ -9,6 +9,7 @@ use Utopia\Queue\Client; use Utopia\Queue\Connection; use Utopia\Validator\Integer; use Utopia\Validator\WhiteList; +use Utopia\Validator\Wildcard; class QueueRetry extends Action { @@ -36,18 +37,24 @@ class QueueRetry extends Action Event::MIGRATIONS_QUEUE_NAME, Event::HAMSTER_CLASS_NAME ]), 'Queue name') - ->param('limit', 0, new Integer(true), 'jobs limit', true) + ->param('limit', null, new Wildcard(), 'jobs limit', true) ->inject('queue') ->callback(fn ($name, $limit, $queue) => $this->action($name, $limit, $queue)); } /** * @param string $name The name of the queue to retry jobs from - * @param int $limit + * @param mixed $limit * @param Connection $queue */ - public function action(string $name, int $limit, Connection $queue): void + public function action(string $name, mixed $limit, Connection $queue): void { + + if (!\is_numeric($limit) && $limit !== null) { + Console::error('$limit parameter should be an integer'); + return; + } + if (!$name) { Console::error('Missing required parameter $name'); return; From 658396b4a857739bb83f50461ae6f950c83ae133 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 28 Feb 2024 21:09:10 +0200 Subject: [PATCH 3/4] adding limit to queue retry --- src/Appwrite/Platform/Tasks/QueueRetry.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/QueueRetry.php b/src/Appwrite/Platform/Tasks/QueueRetry.php index 6c7714ff04..f34448d881 100644 --- a/src/Appwrite/Platform/Tasks/QueueRetry.php +++ b/src/Appwrite/Platform/Tasks/QueueRetry.php @@ -37,7 +37,7 @@ class QueueRetry extends Action Event::MIGRATIONS_QUEUE_NAME, Event::HAMSTER_CLASS_NAME ]), 'Queue name') - ->param('limit', null, new Wildcard(), 'jobs limit', true) + ->param('limit', 0, new Wildcard(), 'jobs limit', true) ->inject('queue') ->callback(fn ($name, $limit, $queue) => $this->action($name, $limit, $queue)); } @@ -50,18 +50,14 @@ class QueueRetry extends Action public function action(string $name, mixed $limit, Connection $queue): void { - if (!\is_numeric($limit) && $limit !== null) { - Console::error('$limit parameter should be an integer'); - return; - } - if (!$name) { Console::error('Missing required parameter $name'); return; } + $limit = (int)$limit; $queueClient = new Client($name, $queue); - + var_dump($limit); if ($queueClient->countFailedJobs() === 0) { Console::error('No failed jobs found.'); return; From 1a59361200e85cbea84dbda3642e1f5eb8da0570 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 28 Feb 2024 21:15:59 +0200 Subject: [PATCH 4/4] adding limit to queue retry --- src/Appwrite/Platform/Tasks/QueueRetry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/QueueRetry.php b/src/Appwrite/Platform/Tasks/QueueRetry.php index f34448d881..2781d9a3f7 100644 --- a/src/Appwrite/Platform/Tasks/QueueRetry.php +++ b/src/Appwrite/Platform/Tasks/QueueRetry.php @@ -57,7 +57,7 @@ class QueueRetry extends Action $limit = (int)$limit; $queueClient = new Client($name, $queue); - var_dump($limit); + if ($queueClient->countFailedJobs() === 0) { Console::error('No failed jobs found.'); return;