From 01d76a1746f7f99772353957d1086a463b609d71 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 4 Jan 2024 13:00:25 +0000 Subject: [PATCH] Add Queue Retry Command to Appwrite --- Dockerfile | 1 + bin/retry | 3 ++ composer.json | 6 +++- composer.lock | 44 +++++++++++++++--------- src/Appwrite/Platform/Services/Tasks.php | 2 ++ src/Appwrite/Platform/Tasks/Retry.php | 39 +++++++++++++++++++++ 6 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 bin/retry create mode 100644 src/Appwrite/Platform/Tasks/Retry.php diff --git a/Dockerfile b/Dockerfile index 2f85f2cc43..b655c9c203 100755 --- a/Dockerfile +++ b/Dockerfile @@ -85,6 +85,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/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/retry b/bin/retry new file mode 100644 index 0000000000..f6daeda97a --- /dev/null +++ b/bin/retry @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php retry $@ \ No newline at end of file diff --git a/composer.json b/composer.json index 413160a7fa..9d0e34ac27 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.5.*", + "utopia-php/queue": "dev-feat-retry", "utopia-php/registry": "0.5.*", "utopia-php/storage": "0.18.*", "utopia-php/swoole": "0.5.*", @@ -82,6 +82,10 @@ { "url": "https://github.com/appwrite/runtimes.git", "type": "git" + }, + { + "url": "https://github.com/utopia-php/queue.git", + "type": "git" } ], "require-dev": { diff --git a/composer.lock b/composer.lock index acd65d61a1..8106c5dc1b 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": "7041499af2e7b23795d8ef82c9d7a072", + "content-hash": "6ffcf14db0d3b00a5e85967a6deae4be", "packages": [ { "name": "adhocore/jwt", @@ -2629,17 +2629,11 @@ }, { "name": "utopia-php/queue", - "version": "0.5.3", + "version": "dev-feat-retry", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "8e8b6cb27172713fe5d8b7b092ce68516caf129a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/8e8b6cb27172713fe5d8b7b092ce68516caf129a", - "reference": "8e8b6cb27172713fe5d8b7b092ce68516caf129a", - "shasum": "" + "reference": "9930184b3e9f5c92b5298763968f4b1d92fbe6e2" }, "require": { "php": ">=8.0", @@ -2663,7 +2657,25 @@ "Utopia\\Queue\\": "src/Queue" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Tests\\E2E\\": "tests/Queue/E2E" + } + }, + "scripts": { + "test": [ + "phpunit" + ], + "analyse": [ + "vendor/bin/phpstan analyse" + ], + "format": [ + "vendor/bin/pint" + ], + "lint": [ + "vendor/bin/pint --test" + ] + }, "license": [ "MIT" ], @@ -2675,18 +2687,14 @@ ], "description": "A powerful task queue.", "keywords": [ - "Tasks", "framework", "php", "queue", + "tasks", "upf", "utopia" ], - "support": { - "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.5.3" - }, - "time": "2023-05-24T19:06:04+00:00" + "time": "2023-12-29T15:06:54+00:00" }, { "name": "utopia-php/registry", @@ -5823,7 +5831,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/queue": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index dc6ddc1a5b..0b8e1d4678 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -21,6 +21,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\Retry; class Tasks extends Service { @@ -46,6 +47,7 @@ class Tasks extends Service ->addAction(DeleteOrphanedProjects::getName(), new DeleteOrphanedProjects()) ->addAction(PatchRecreateRepositoriesDocuments::getName(), new PatchRecreateRepositoriesDocuments()) ->addAction(GetMigrationStats::getName(), new GetMigrationStats()) + ->addAction(Retry::getName(), new Retry()) ; } diff --git a/src/Appwrite/Platform/Tasks/Retry.php b/src/Appwrite/Platform/Tasks/Retry.php new file mode 100644 index 0000000000..15e56a3f97 --- /dev/null +++ b/src/Appwrite/Platform/Tasks/Retry.php @@ -0,0 +1,39 @@ +desc('Retry Queue') + ->param('name', '', new Text(128), 'Queue name') + ->inject('queue') + ->callback(fn ($queueName, $queue) => $this->action($queueName, $queue)); + } + + public function action(string $queueName, Connection $queue): void + { + $queueClient = new Client($queueName, $queue); + + if ($queueClient->sumFailedJobs() === 0) { + Console::error('Found no jobs to retry, are you sure you have the right queue name?'); + return; + } + + $queueClient->retry(); + } +} \ No newline at end of file