From 216a5d7001d44acb15886525d4bf96c50c6b6a29 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 11:11:18 +0000 Subject: [PATCH 1/4] Add queue management commands --- Dockerfile | 3 + bin/queue-count-failed | 3 + bin/queue-count-processing | 3 + bin/queue-count-success | 3 + .../Platform/Tasks/QueueCountFailed.php | 57 +++++++++++++++++++ .../Platform/Tasks/QueueCountProcessing.php | 57 +++++++++++++++++++ .../Platform/Tasks/QueueCountSuccess.php | 57 +++++++++++++++++++ 7 files changed, 183 insertions(+) create mode 100644 bin/queue-count-failed create mode 100644 bin/queue-count-processing create mode 100644 bin/queue-count-success create mode 100644 src/Appwrite/Platform/Tasks/QueueCountFailed.php create mode 100644 src/Appwrite/Platform/Tasks/QueueCountProcessing.php create mode 100644 src/Appwrite/Platform/Tasks/QueueCountSuccess.php diff --git a/Dockerfile b/Dockerfile index ea14bca383..9f3ee9b700 100755 --- a/Dockerfile +++ b/Dockerfile @@ -85,6 +85,9 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/test && \ chmod +x /usr/local/bin/vars && \ chmod +x /usr/local/bin/queue-retry && \ + chmod +x /usr/local/bin/queue-count-failed && \ + chmod +x /usr/local/bin/queue-count-processing && \ + chmod +x /usr/local/bin/queue-count-success && \ chmod +x /usr/local/bin/worker-audits && \ chmod +x /usr/local/bin/worker-certificates && \ chmod +x /usr/local/bin/worker-databases && \ diff --git a/bin/queue-count-failed b/bin/queue-count-failed new file mode 100644 index 0000000000..9a40edcae9 --- /dev/null +++ b/bin/queue-count-failed @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php queue-count-failed $@ \ No newline at end of file diff --git a/bin/queue-count-processing b/bin/queue-count-processing new file mode 100644 index 0000000000..4729642e44 --- /dev/null +++ b/bin/queue-count-processing @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php queue-count-processing $@ \ No newline at end of file diff --git a/bin/queue-count-success b/bin/queue-count-success new file mode 100644 index 0000000000..dc129a5687 --- /dev/null +++ b/bin/queue-count-success @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php queue-count-success $@ \ No newline at end of file diff --git a/src/Appwrite/Platform/Tasks/QueueCountFailed.php b/src/Appwrite/Platform/Tasks/QueueCountFailed.php new file mode 100644 index 0000000000..30d9bd9121 --- /dev/null +++ b/src/Appwrite/Platform/Tasks/QueueCountFailed.php @@ -0,0 +1,57 @@ +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 new file mode 100644 index 0000000000..cb547afb6d --- /dev/null +++ b/src/Appwrite/Platform/Tasks/QueueCountProcessing.php @@ -0,0 +1,57 @@ +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 new file mode 100644 index 0000000000..ad782fc968 --- /dev/null +++ b/src/Appwrite/Platform/Tasks/QueueCountSuccess.php @@ -0,0 +1,57 @@ +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."); + } +} From 4c96f7676240ac2c766592e23faedc9482849d8f Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 11:20:13 +0000 Subject: [PATCH 2/4] Run Linter --- src/Appwrite/Platform/Tasks/QueueCountFailed.php | 2 +- src/Appwrite/Platform/Tasks/QueueCountProcessing.php | 2 +- src/Appwrite/Platform/Tasks/QueueCountSuccess.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/QueueCountFailed.php b/src/Appwrite/Platform/Tasks/QueueCountFailed.php index 30d9bd9121..e605af1ccc 100644 --- a/src/Appwrite/Platform/Tasks/QueueCountFailed.php +++ b/src/Appwrite/Platform/Tasks/QueueCountFailed.php @@ -52,6 +52,6 @@ class QueueCountFailed extends Action $queueClient = new Client($name, $queue); - Console::log("Queue: '".$name."' Currently has " . $queueClient->countFailedJobs() . " failed jobs."); + 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 index cb547afb6d..b5373e2969 100644 --- a/src/Appwrite/Platform/Tasks/QueueCountProcessing.php +++ b/src/Appwrite/Platform/Tasks/QueueCountProcessing.php @@ -52,6 +52,6 @@ class QueueCountProcessing extends Action $queueClient = new Client($name, $queue); - Console::log("Queue: '".$name."' Currently has " . $queueClient->countProcessingJobs() . " processing jobs."); + 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 index ad782fc968..f6b4b1a562 100644 --- a/src/Appwrite/Platform/Tasks/QueueCountSuccess.php +++ b/src/Appwrite/Platform/Tasks/QueueCountSuccess.php @@ -52,6 +52,6 @@ class QueueCountSuccess extends Action $queueClient = new Client($name, $queue); - Console::log("Queue: '".$name."' Currently has " . $queueClient->countSuccessfulJobs() . " success jobs."); + Console::log("Queue: '" . $name . "' Currently has " . $queueClient->countSuccessfulJobs() . " success jobs."); } } From 186772cc15012f470bbc0ab32519d1f16044ce0d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 15:51:28 +0000 Subject: [PATCH 3/4] 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."); - } -} From 6ceeacbe039ef608d2afa3dbb71ba615cfe3d022 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 26 Jan 2024 15:52:58 +0000 Subject: [PATCH 4/4] Run Linter --- src/Appwrite/Platform/Tasks/QueueCount.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/QueueCount.php b/src/Appwrite/Platform/Tasks/QueueCount.php index ef8984dc75..61d4750fac 100644 --- a/src/Appwrite/Platform/Tasks/QueueCount.php +++ b/src/Appwrite/Platform/Tasks/QueueCount.php @@ -59,7 +59,7 @@ class QueueCount extends Action $queueClient = new Client($name, $queue); $count = 0; - + switch ($type) { case 'success': $count = $queueClient->countSuccessfulJobs();