From 01d76a1746f7f99772353957d1086a463b609d71 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 4 Jan 2024 13:00:25 +0000 Subject: [PATCH 01/11] 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 From 4199126984e6660228f555f044161014867097a1 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 4 Jan 2024 13:04:51 +0000 Subject: [PATCH 02/11] Run Linter --- src/Appwrite/Platform/Tasks/Retry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/Retry.php b/src/Appwrite/Platform/Tasks/Retry.php index 15e56a3f97..a2cf883393 100644 --- a/src/Appwrite/Platform/Tasks/Retry.php +++ b/src/Appwrite/Platform/Tasks/Retry.php @@ -36,4 +36,4 @@ class Retry extends Action $queueClient->retry(); } -} \ No newline at end of file +} From d9c04f4fc099e891ddd131fe230818779aef8dee Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 5 Jan 2024 12:37:03 +0000 Subject: [PATCH 03/11] Update src/Appwrite/Platform/Tasks/Retry.php Co-authored-by: Eldad A. Fux --- src/Appwrite/Platform/Tasks/Retry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/Retry.php b/src/Appwrite/Platform/Tasks/Retry.php index a2cf883393..9e8f28ab78 100644 --- a/src/Appwrite/Platform/Tasks/Retry.php +++ b/src/Appwrite/Platform/Tasks/Retry.php @@ -30,7 +30,7 @@ class Retry extends Action $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?'); + Console::error('No failed jobs found.'); return; } From da014b0ad3e93579c512979c83b40297e91a8627 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 17 Jan 2024 15:49:50 +0000 Subject: [PATCH 04/11] Rename retry to queue-retry --- Dockerfile | 2 +- bin/{retry => queue-retry} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename bin/{retry => queue-retry} (100%) diff --git a/Dockerfile b/Dockerfile index b655c9c203..e39890dd60 100755 --- a/Dockerfile +++ b/Dockerfile @@ -85,7 +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/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/retry b/bin/queue-retry similarity index 100% rename from bin/retry rename to bin/queue-retry From 1e247bdde19f2b2eeac3eaeb71aa58383480e29c Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 19 Jan 2024 13:18:37 +0000 Subject: [PATCH 05/11] Address Christy's Comments and Update Lib --- composer.json | 6 +- composer.lock | 140 ++++++++++++-------------- src/Appwrite/Platform/Tasks/Retry.php | 21 ++-- 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/composer.json b/composer.json index 9d0e34ac27..9a26b92506 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": "dev-feat-retry", + "utopia-php/queue": "0.7.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "0.18.*", "utopia-php/swoole": "0.5.*", @@ -82,10 +82,6 @@ { "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 8106c5dc1b..f64f2d2b22 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": "6ffcf14db0d3b00a5e85967a6deae4be", + "content-hash": "1f9bea9625c3f7b6421b60f4767f5bb6", "packages": [ { "name": "adhocore/jwt", @@ -277,16 +277,16 @@ }, { "name": "chillerlan/php-settings-container", - "version": "2.1.4", + "version": "2.1.5", "source": { "type": "git", "url": "https://github.com/chillerlan/php-settings-container.git", - "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a" + "reference": "f705310389264c3578fdd9ffb15aa2cd6d91772e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", - "reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/f705310389264c3578fdd9ffb15aa2cd6d91772e", + "reference": "f705310389264c3578fdd9ffb15aa2cd6d91772e", "shasum": "" }, "require": { @@ -294,8 +294,10 @@ "php": "^7.4 || ^8.0" }, "require-dev": { - "phan/phan": "^5.3", - "phpunit/phpunit": "^9.5" + "phan/phan": "^5.4", + "phpcsstandards/php_codesniffer": "^3.8", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": "^9.6" }, "type": "library", "autoload": { @@ -337,7 +339,7 @@ "type": "ko_fi" } ], - "time": "2022-07-05T22:32:14+00:00" + "time": "2024-01-05T23:20:55+00:00" }, { "name": "dragonmantank/cron-expression", @@ -2072,12 +2074,12 @@ "version": "0.31.1", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework.git", + "url": "https://github.com/utopia-php/http.git", "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", "shasum": "" }, @@ -2107,8 +2109,8 @@ "upf" ], "support": { - "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.31.1" + "issues": "https://github.com/utopia-php/http/issues", + "source": "https://github.com/utopia-php/http/tree/0.31.1" }, "time": "2023-12-08T18:47:29+00:00" }, @@ -2629,11 +2631,17 @@ }, { "name": "utopia-php/queue", - "version": "dev-feat-retry", + "version": "0.7.0", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "9930184b3e9f5c92b5298763968f4b1d92fbe6e2" + "reference": "917565256eb94bcab7246f7a746b1a486813761b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/917565256eb94bcab7246f7a746b1a486813761b", + "reference": "917565256eb94bcab7246f7a746b1a486813761b", + "shasum": "" }, "require": { "php": ">=8.0", @@ -2657,25 +2665,7 @@ "Utopia\\Queue\\": "src/Queue" } }, - "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" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2687,14 +2677,18 @@ ], "description": "A powerful task queue.", "keywords": [ + "Tasks", "framework", "php", "queue", - "tasks", "upf", "utopia" ], - "time": "2023-12-29T15:06:54+00:00" + "support": { + "issues": "https://github.com/utopia-php/queue/issues", + "source": "https://github.com/utopia-php/queue/tree/0.7.0" + }, + "time": "2024-01-17T19:00:43+00:00" }, { "name": "utopia-php/registry", @@ -3144,16 +3138,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.36.0", + "version": "0.36.1", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "3a10f1f895ed71120442ff71eb6adec3fd6b4e8a" + "reference": "ca4700bfbbb8bcf1c0d5a49fc5efc38da98d0992" }, "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/ca4700bfbbb8bcf1c0d5a49fc5efc38da98d0992", + "reference": "ca4700bfbbb8bcf1c0d5a49fc5efc38da98d0992", "shasum": "" }, "require": { @@ -3189,9 +3183,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.1" }, - "time": "2023-11-20T10:03:06+00:00" + "time": "2024-01-18T06:24:47+00:00" }, { "name": "doctrine/deprecations", @@ -3495,25 +3489,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.18.0", + "version": "v5.0.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999" + "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4a21235f7e56e713259a6f76bf4b5ea08502b9dc", + "reference": "4a21235f7e56e713259a6f76bf4b5ea08502b9dc", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -3521,7 +3517,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -3545,9 +3541,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.0" }, - "time": "2023-12-10T21:03:43+00:00" + "time": "2024-01-07T17:17:35+00:00" }, { "name": "phar-io/manifest", @@ -3772,16 +3768,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.3", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fad452781b3d774e3337b0c0b245dd8e5a4455fc", + "reference": "fad452781b3d774e3337b0c0b245dd8e5a4455fc", "shasum": "" }, "require": { @@ -3824,9 +3820,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.0" }, - "time": "2023-08-12T11:01:26+00:00" + "time": "2024-01-11T11:49:22+00:00" }, { "name": "phpspec/prophecy", @@ -3899,16 +3895,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.5", + "version": "1.25.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc" + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fedf211ff14ec8381c9bf5714e33a7a552dd1acc", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", "shasum": "" }, "require": { @@ -3940,9 +3936,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.5" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" }, - "time": "2023-12-16T09:33:33+00:00" + "time": "2024-01-04T17:06:16+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5382,16 +5378,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", "shasum": "" }, "require": { @@ -5401,11 +5397,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -5458,7 +5454,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-01-11T20:47:48+00:00" }, { "name": "swoole/ide-helper", @@ -5831,9 +5827,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/queue": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Tasks/Retry.php b/src/Appwrite/Platform/Tasks/Retry.php index 9e8f28ab78..d78e309bba 100644 --- a/src/Appwrite/Platform/Tasks/Retry.php +++ b/src/Appwrite/Platform/Tasks/Retry.php @@ -12,24 +12,33 @@ class Retry extends Action { public static function getName(): string { - return 'retry'; + return 'retry-jobs'; } public function __construct() { $this - ->desc('Retry Queue') + ->desc('Retry failed jobs from a specific queue identified by the name parameter') ->param('name', '', new Text(128), 'Queue name') ->inject('queue') - ->callback(fn ($queueName, $queue) => $this->action($queueName, $queue)); + ->callback(fn ($name, $queue) => $this->action($name, $queue)); } - public function action(string $queueName, Connection $queue): void + /** + * @param string $name The name of the queue to retry jobs from + * @param Connection $queue + */ + public function action(string $name, Connection $queue): void { - $queueClient = new Client($queueName, $queue); + if (!$name) { + Console::error('Missing required parameter $name'); + return; + } - if ($queueClient->sumFailedJobs() === 0) { + $queueClient = new Client($name, $queue); + + if ($queueClient->countFailedJobs() === 0) { Console::error('No failed jobs found.'); return; } From 2a65dfcc5d3c68bc88d12b86ad7ed604688512c0 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 22 Jan 2024 13:51:14 +0000 Subject: [PATCH 06/11] Update Dockerfile Co-authored-by: Christy Jacob --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e39890dd60..385f53a144 100755 --- a/Dockerfile +++ b/Dockerfile @@ -85,7 +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/queue-retry && \ + chmod +x /usr/local/bin/retry-jobs && \ chmod +x /usr/local/bin/worker-audits && \ chmod +x /usr/local/bin/worker-certificates && \ chmod +x /usr/local/bin/worker-databases && \ From 09a7fc90634acc8e45f69e7cce1819dc562fdfd2 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 22 Jan 2024 13:51:20 +0000 Subject: [PATCH 07/11] Update bin/queue-retry Co-authored-by: Christy Jacob --- bin/queue-retry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/queue-retry b/bin/queue-retry index f6daeda97a..afc78aacf3 100644 --- a/bin/queue-retry +++ b/bin/queue-retry @@ -1,3 +1,3 @@ #!/bin/sh -php /usr/src/code/app/cli.php retry $@ \ No newline at end of file +php /usr/src/code/app/cli.php retry-jobs $@ \ No newline at end of file From f3579b3f12cf973ef523b7fc9841ba88996929f6 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 22 Jan 2024 16:50:45 +0000 Subject: [PATCH 08/11] Address Christy's Comments --- bin/{queue-retry => retry-jobs} | 0 src/Appwrite/Platform/Services/Tasks.php | 4 ++-- src/Appwrite/Platform/Tasks/{Retry.php => RetryJobs.php} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename bin/{queue-retry => retry-jobs} (100%) rename src/Appwrite/Platform/Tasks/{Retry.php => RetryJobs.php} (97%) diff --git a/bin/queue-retry b/bin/retry-jobs similarity index 100% rename from bin/queue-retry rename to bin/retry-jobs diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index 0b8e1d4678..82e7b2454a 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -21,7 +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; +use Appwrite\Platform\Tasks\RetryJobs; class Tasks extends Service { @@ -47,7 +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()) + ->addAction(RetryJobs::getName(), new RetryJobs()) ; } diff --git a/src/Appwrite/Platform/Tasks/Retry.php b/src/Appwrite/Platform/Tasks/RetryJobs.php similarity index 97% rename from src/Appwrite/Platform/Tasks/Retry.php rename to src/Appwrite/Platform/Tasks/RetryJobs.php index d78e309bba..6746690899 100644 --- a/src/Appwrite/Platform/Tasks/Retry.php +++ b/src/Appwrite/Platform/Tasks/RetryJobs.php @@ -8,7 +8,7 @@ use Utopia\Queue\Client; use Utopia\Queue\Connection; use Utopia\Validator\Text; -class Retry extends Action +class RetryJobs extends Action { public static function getName(): string { From 351abe50d3ef3cc98089603f2f0a63dd943a9f7b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 24 Jan 2024 14:45:17 +0000 Subject: [PATCH 09/11] Update src/Appwrite/Platform/Services/Tasks.php Co-authored-by: Christy Jacob --- src/Appwrite/Platform/Services/Tasks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index 82e7b2454a..62c832fcd1 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -21,7 +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\RetryJobs; +use Appwrite\Platform\Tasks\QueueRetry; class Tasks extends Service { From d3e9d033297d0f738454c0ad8beaa41352555e40 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 24 Jan 2024 14:45:24 +0000 Subject: [PATCH 10/11] Update src/Appwrite/Platform/Tasks/RetryJobs.php Co-authored-by: Christy Jacob --- src/Appwrite/Platform/Tasks/RetryJobs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/RetryJobs.php b/src/Appwrite/Platform/Tasks/RetryJobs.php index 6746690899..5167b899b2 100644 --- a/src/Appwrite/Platform/Tasks/RetryJobs.php +++ b/src/Appwrite/Platform/Tasks/RetryJobs.php @@ -12,7 +12,7 @@ class RetryJobs extends Action { public static function getName(): string { - return 'retry-jobs'; + return 'queue-retry'; } From ab2d830cc0357b1ec6ae8ba00f1d04aba19f2e70 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 24 Jan 2024 17:44:29 +0000 Subject: [PATCH 11/11] Address comments --- Dockerfile | 2 +- bin/queue-retry | 3 +++ bin/retry-jobs | 3 --- src/Appwrite/Platform/Tasks/RetryJobs.php | 20 +++++++++++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 bin/queue-retry delete mode 100644 bin/retry-jobs diff --git a/Dockerfile b/Dockerfile index 385f53a144..e39890dd60 100755 --- a/Dockerfile +++ b/Dockerfile @@ -85,7 +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-jobs && \ + 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/bin/retry-jobs b/bin/retry-jobs deleted file mode 100644 index afc78aacf3..0000000000 --- a/bin/retry-jobs +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -php /usr/src/code/app/cli.php retry-jobs $@ \ No newline at end of file diff --git a/src/Appwrite/Platform/Tasks/RetryJobs.php b/src/Appwrite/Platform/Tasks/RetryJobs.php index 5167b899b2..90a9bceefb 100644 --- a/src/Appwrite/Platform/Tasks/RetryJobs.php +++ b/src/Appwrite/Platform/Tasks/RetryJobs.php @@ -2,11 +2,14 @@ namespace Appwrite\Platform\Tasks; +use Appwrite\Event\Event; +use Twig\Node\Expression\Test\EvenTest; use Utopia\CLI\Console; use Utopia\Platform\Action; use Utopia\Queue\Client; use Utopia\Queue\Connection; use Utopia\Validator\Text; +use Utopia\Validator\WhiteList; class RetryJobs extends Action { @@ -20,7 +23,20 @@ class RetryJobs extends Action { $this ->desc('Retry failed jobs from a specific queue identified by the name parameter') - ->param('name', '', new Text(128), 'Queue name') + ->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)); } @@ -43,6 +59,8 @@ class RetryJobs extends Action return; } + Console::log('Retrying failed jobs...'); + $queueClient->retry(); } }