From 186772cc15012f470bbc0ab32519d1f16044ce0d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 15:51:28 +0000 Subject: [PATCH] Simplify commands, fix queue consts --- bin/queue-count-failed | 2 +- bin/queue-count-processing | 2 +- bin/queue-count-success | 2 +- src/Appwrite/Platform/Services/Tasks.php | 2 + src/Appwrite/Platform/Tasks/QueueCount.php | 77 +++++++++++++++++++ .../Platform/Tasks/QueueCountFailed.php | 57 -------------- .../Platform/Tasks/QueueCountProcessing.php | 57 -------------- .../Platform/Tasks/QueueCountSuccess.php | 57 -------------- 8 files changed, 82 insertions(+), 174 deletions(-) create mode 100644 src/Appwrite/Platform/Tasks/QueueCount.php delete mode 100644 src/Appwrite/Platform/Tasks/QueueCountFailed.php delete mode 100644 src/Appwrite/Platform/Tasks/QueueCountProcessing.php delete mode 100644 src/Appwrite/Platform/Tasks/QueueCountSuccess.php diff --git a/bin/queue-count-failed b/bin/queue-count-failed index 9a40edcae9..ca8f2b4291 100644 --- a/bin/queue-count-failed +++ b/bin/queue-count-failed @@ -1,3 +1,3 @@ #!/bin/sh -php /usr/src/code/app/cli.php queue-count-failed $@ \ No newline at end of file +php /usr/src/code/app/cli.php queue-count --type=failed $@ \ No newline at end of file diff --git a/bin/queue-count-processing b/bin/queue-count-processing index 4729642e44..325d86111d 100644 --- a/bin/queue-count-processing +++ b/bin/queue-count-processing @@ -1,3 +1,3 @@ #!/bin/sh -php /usr/src/code/app/cli.php queue-count-processing $@ \ No newline at end of file +php /usr/src/code/app/cli.php queue-count --type=processing $@ \ No newline at end of file diff --git a/bin/queue-count-success b/bin/queue-count-success index dc129a5687..34fc54b4c1 100644 --- a/bin/queue-count-success +++ b/bin/queue-count-success @@ -1,3 +1,3 @@ #!/bin/sh -php /usr/src/code/app/cli.php queue-count-success $@ \ No newline at end of file +php /usr/src/code/app/cli.php queue-count --type=success $@ \ No newline at end of file diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index 53bc954f07..eb06c425c0 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -22,6 +22,7 @@ use Appwrite\Platform\Tasks\GetMigrationStats; use Appwrite\Platform\Tasks\PatchRecreateRepositoriesDocuments; use Appwrite\Platform\Tasks\QueueRetry; use Appwrite\Platform\Tasks\CreateInfMetric; +use Appwrite\Platform\Tasks\QueueCount; class Tasks extends Service { @@ -47,6 +48,7 @@ class Tasks extends Service ->addAction(PatchRecreateRepositoriesDocuments::getName(), new PatchRecreateRepositoriesDocuments()) ->addAction(GetMigrationStats::getName(), new GetMigrationStats()) ->addAction(QueueRetry::getName(), new QueueRetry()) + ->addAction(QueueCount::getName(), new QueueCount()) ->addAction(CreateInfMetric::getName(), new CreateInfMetric()) ; } diff --git a/src/Appwrite/Platform/Tasks/QueueCount.php b/src/Appwrite/Platform/Tasks/QueueCount.php new file mode 100644 index 0000000000..ef8984dc75 --- /dev/null +++ b/src/Appwrite/Platform/Tasks/QueueCount.php @@ -0,0 +1,77 @@ +desc('Return the number of from a specific queue identified by the name parameter with a specific type') + ->param('name', '', new WhiteList([ + Event::DATABASE_QUEUE_NAME, + Event::DELETE_QUEUE_NAME, + Event::AUDITS_QUEUE_NAME, + Event::MAILS_QUEUE_NAME, + Event::FUNCTIONS_QUEUE_NAME, + Event::USAGE_QUEUE_NAME, + Event::WEBHOOK_QUEUE_NAME, + Event::CERTIFICATES_QUEUE_NAME, + Event::BUILDS_QUEUE_NAME, + Event::MESSAGING_QUEUE_NAME, + Event::MIGRATIONS_QUEUE_NAME, + Event::HAMSTER_QUEUE_NAME + ]), 'Queue name') + ->param('type', '', new WhiteList([ + 'success', + 'failed', + 'processing', + ]), 'Queue type') + ->inject('queue') + ->callback(fn ($name, $type, $queue) => $this->action($name, $type, $queue)); + } + + /** + * @param string $name The name of the queue to count the jobs from + * @param string $type The type of jobs to count + * @param Connection $queue + */ + public function action(string $name, string $type, Connection $queue): void + { + if (!$name) { + Console::error('Missing required parameter $name'); + return; + } + + $queueClient = new Client($name, $queue); + + $count = 0; + + switch ($type) { + case 'success': + $count = $queueClient->countSuccessfulJobs(); + break; + case 'failed': + $count = $queueClient->countFailedJobs(); + break; + case 'processing': + $count = $queueClient->countProcessingJobs(); + break; + }; + + Console::log("Queue: '{$name}' has {$count} {$type} jobs."); + } +} diff --git a/src/Appwrite/Platform/Tasks/QueueCountFailed.php b/src/Appwrite/Platform/Tasks/QueueCountFailed.php deleted file mode 100644 index e605af1ccc..0000000000 --- a/src/Appwrite/Platform/Tasks/QueueCountFailed.php +++ /dev/null @@ -1,57 +0,0 @@ -desc('Return the number of failed jobs from a specific queue identified by the name parameter') - ->param('name', '', new WhiteList([ - Event::DATABASE_QUEUE_NAME, - Event::DELETE_QUEUE_NAME, - Event::AUDITS_QUEUE_NAME, - Event::MAILS_QUEUE_NAME, - Event::FUNCTIONS_QUEUE_NAME, - Event::USAGE_QUEUE_NAME, - Event::WEBHOOK_CLASS_NAME, - Event::CERTIFICATES_QUEUE_NAME, - Event::BUILDS_QUEUE_NAME, - Event::MESSAGING_QUEUE_NAME, - Event::MIGRATIONS_QUEUE_NAME, - Event::HAMSTER_CLASS_NAME - ]), 'Queue name') - ->inject('queue') - ->callback(fn ($name, $queue) => $this->action($name, $queue)); - } - - /** - * @param string $name The name of the queue to count the failed jobs from - * @param Connection $queue - */ - public function action(string $name, Connection $queue): void - { - if (!$name) { - Console::error('Missing required parameter $name'); - return; - } - - $queueClient = new Client($name, $queue); - - Console::log("Queue: '" . $name . "' Currently has " . $queueClient->countFailedJobs() . " failed jobs."); - } -} diff --git a/src/Appwrite/Platform/Tasks/QueueCountProcessing.php b/src/Appwrite/Platform/Tasks/QueueCountProcessing.php deleted file mode 100644 index b5373e2969..0000000000 --- a/src/Appwrite/Platform/Tasks/QueueCountProcessing.php +++ /dev/null @@ -1,57 +0,0 @@ -desc('Return the number of currently processing jobs from a specific queue identified by the name parameter') - ->param('name', '', new WhiteList([ - Event::DATABASE_QUEUE_NAME, - Event::DELETE_QUEUE_NAME, - Event::AUDITS_QUEUE_NAME, - Event::MAILS_QUEUE_NAME, - Event::FUNCTIONS_QUEUE_NAME, - Event::USAGE_QUEUE_NAME, - Event::WEBHOOK_CLASS_NAME, - Event::CERTIFICATES_QUEUE_NAME, - Event::BUILDS_QUEUE_NAME, - Event::MESSAGING_QUEUE_NAME, - Event::MIGRATIONS_QUEUE_NAME, - Event::HAMSTER_CLASS_NAME - ]), 'Queue name') - ->inject('queue') - ->callback(fn ($name, $queue) => $this->action($name, $queue)); - } - - /** - * @param string $name The name of the queue to count the processing jobs from - * @param Connection $queue - */ - public function action(string $name, Connection $queue): void - { - if (!$name) { - Console::error('Missing required parameter $name'); - return; - } - - $queueClient = new Client($name, $queue); - - Console::log("Queue: '" . $name . "' Currently has " . $queueClient->countProcessingJobs() . " processing jobs."); - } -} diff --git a/src/Appwrite/Platform/Tasks/QueueCountSuccess.php b/src/Appwrite/Platform/Tasks/QueueCountSuccess.php deleted file mode 100644 index f6b4b1a562..0000000000 --- a/src/Appwrite/Platform/Tasks/QueueCountSuccess.php +++ /dev/null @@ -1,57 +0,0 @@ -desc('Return the number of successful jobs from a specific queue identified by the name parameter') - ->param('name', '', new WhiteList([ - Event::DATABASE_QUEUE_NAME, - Event::DELETE_QUEUE_NAME, - Event::AUDITS_QUEUE_NAME, - Event::MAILS_QUEUE_NAME, - Event::FUNCTIONS_QUEUE_NAME, - Event::USAGE_QUEUE_NAME, - Event::WEBHOOK_CLASS_NAME, - Event::CERTIFICATES_QUEUE_NAME, - Event::BUILDS_QUEUE_NAME, - Event::MESSAGING_QUEUE_NAME, - Event::MIGRATIONS_QUEUE_NAME, - Event::HAMSTER_CLASS_NAME - ]), 'Queue name') - ->inject('queue') - ->callback(fn ($name, $queue) => $this->action($name, $queue)); - } - - /** - * @param string $name The name of the queue to count the successful jobs from - * @param Connection $queue - */ - public function action(string $name, Connection $queue): void - { - if (!$name) { - Console::error('Missing required parameter $name'); - return; - } - - $queueClient = new Client($name, $queue); - - Console::log("Queue: '" . $name . "' Currently has " . $queueClient->countSuccessfulJobs() . " success jobs."); - } -}