diff --git a/Dockerfile b/Dockerfile index 324a3a5484..ea14bca383 100755 --- a/Dockerfile +++ b/Dockerfile @@ -84,6 +84,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/ssl && \ chmod +x /usr/local/bin/test && \ chmod +x /usr/local/bin/vars && \ + chmod +x /usr/local/bin/queue-retry && \ 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-retry b/bin/queue-retry new file mode 100644 index 0000000000..f9473e6b07 --- /dev/null +++ b/bin/queue-retry @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php queue-retry $@ \ No newline at end of file diff --git a/composer.json b/composer.json index 83bcd26468..94b1d8f41f 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "utopia-php/platform": "0.5.*", "utopia-php/pools": "0.4.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "0.6.*", + "utopia-php/queue": "0.7.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "0.18.*", "utopia-php/swoole": "0.5.*", diff --git a/composer.lock b/composer.lock index 61a8f297d7..7507243862 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1b3fd261ed93452413b8e6ba77dbab55", + "content-hash": "35dcde03d0eb9a0d27de653b9fa038d4", "packages": [ { "name": "adhocore/jwt", @@ -1353,16 +1353,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.0", + "version": "0.33.1", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd" + "reference": "b745607aa1875554a0ad52e28f6db918da1ce11c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/e3ff6b933082d57b48e7c4267bb605c0bf2250fd", - "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd", + "url": "https://api.github.com/repos/utopia-php/http/zipball/b745607aa1875554a0ad52e28f6db918da1ce11c", + "reference": "b745607aa1875554a0ad52e28f6db918da1ce11c", "shasum": "" }, "require": { @@ -1392,9 +1392,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.0" + "source": "https://github.com/utopia-php/http/tree/0.33.1" }, - "time": "2024-01-08T13:30:27+00:00" + "time": "2024-01-17T16:48:32+00:00" }, { "name": "utopia-php/image", @@ -1913,16 +1913,16 @@ }, { "name": "utopia-php/queue", - "version": "0.6.0", + "version": "0.7.0", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "0120bd21904cb2bee34e4571b1737589ffff0eb1" + "reference": "917565256eb94bcab7246f7a746b1a486813761b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/0120bd21904cb2bee34e4571b1737589ffff0eb1", - "reference": "0120bd21904cb2bee34e4571b1737589ffff0eb1", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/917565256eb94bcab7246f7a746b1a486813761b", + "reference": "917565256eb94bcab7246f7a746b1a486813761b", "shasum": "" }, "require": { @@ -1968,9 +1968,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.6.0" + "source": "https://github.com/utopia-php/queue/tree/0.7.0" }, - "time": "2023-10-16T16:59:45+00:00" + "time": "2024-01-17T19:00:43+00:00" }, { "name": "utopia-php/registry", @@ -2420,16 +2420,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.36.0", + "version": "0.36.2", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a" + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/0aa67479d75f0e0cb7b60454031534d7f0abaece", + "reference": "0aa67479d75f0e0cb7b60454031534d7f0abaece", "shasum": "" }, "require": { @@ -2465,9 +2465,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.36.0" + "source": "https://github.com/appwrite/sdk-generator/tree/0.36.2" }, - "time": "2023-11-20T10:03:06+00:00" + "time": "2024-01-19T01:04:35+00:00" }, { "name": "doctrine/deprecations", diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index bd5f404da2..53bc954f07 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -20,6 +20,7 @@ use Appwrite\Platform\Tasks\Upgrade; use Appwrite\Platform\Tasks\DeleteOrphanedProjects; use Appwrite\Platform\Tasks\GetMigrationStats; use Appwrite\Platform\Tasks\PatchRecreateRepositoriesDocuments; +use Appwrite\Platform\Tasks\QueueRetry; use Appwrite\Platform\Tasks\CreateInfMetric; class Tasks extends Service @@ -45,8 +46,8 @@ class Tasks extends Service ->addAction(DeleteOrphanedProjects::getName(), new DeleteOrphanedProjects()) ->addAction(PatchRecreateRepositoriesDocuments::getName(), new PatchRecreateRepositoriesDocuments()) ->addAction(GetMigrationStats::getName(), new GetMigrationStats()) + ->addAction(QueueRetry::getName(), new QueueRetry()) ->addAction(CreateInfMetric::getName(), new CreateInfMetric()) - ; } } diff --git a/src/Appwrite/Platform/Tasks/QueueRetry.php b/src/Appwrite/Platform/Tasks/QueueRetry.php new file mode 100644 index 0000000000..cba68f9936 --- /dev/null +++ b/src/Appwrite/Platform/Tasks/QueueRetry.php @@ -0,0 +1,64 @@ +desc('Retry 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 retry 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); + + if ($queueClient->countFailedJobs() === 0) { + Console::error('No failed jobs found.'); + return; + } + + Console::log('Retrying failed jobs...'); + + $queueClient->retry(); + } +} diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index ece4956863..4d5eb4b803 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -978,7 +978,7 @@ trait DatabasesBase ]); $this->assertEquals(400, $badEnum['headers']['status-code']); - $this->assertEquals('Invalid `elements` param: Value must a valid array and Value must be a valid string and at least 1 chars and no longer than 255 chars', $badEnum['body']['message']); + $this->assertEquals('Invalid `elements` param: Value must a valid array no longer than 100 items and Value must be a valid string and at least 1 chars and no longer than 255 chars', $badEnum['body']['message']); return $data; }