From 02093d67d8d5503aa33936334eb791f4efe9b0a3 Mon Sep 17 00:00:00 2001 From: Josh Salway Date: Mon, 20 Apr 2026 10:48:16 +1000 Subject: [PATCH] Add `$tries = 3` to tenant lifecycle jobs Adds a bounded retry count to CreateDatabase, MigrateDatabase, DeleteDatabase, and SeedDatabase. Without $tries, and with queue:work --tries=0 (the default on some platforms including Vapor pre-2.4.1), these jobs retry indefinitely when the tenant database is briefly unreachable. DeleteDatabase is the highest-risk case in the four: if the DB server blips mid-delete, the job loops against it, and any replays after recovery hit a database that may have been partly deleted or may contain data the tenant wanted preserved. `$tries = 3` bounds retries at three attempts; workers then surface the failure to failed_jobs for operator review rather than looping. --- src/Jobs/CreateDatabase.php | 2 ++ src/Jobs/DeleteDatabase.php | 2 ++ src/Jobs/MigrateDatabase.php | 2 ++ src/Jobs/SeedDatabase.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/Jobs/CreateDatabase.php b/src/Jobs/CreateDatabase.php index decdb445..2d4e2240 100644 --- a/src/Jobs/CreateDatabase.php +++ b/src/Jobs/CreateDatabase.php @@ -21,6 +21,8 @@ class CreateDatabase implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public int $tries = 3; + public static bool $ignoreExisting = false; public function __construct( diff --git a/src/Jobs/DeleteDatabase.php b/src/Jobs/DeleteDatabase.php index b59a1c05..e364d7cb 100644 --- a/src/Jobs/DeleteDatabase.php +++ b/src/Jobs/DeleteDatabase.php @@ -18,6 +18,8 @@ class DeleteDatabase implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public int $tries = 3; + public function __construct( protected TenantWithDatabase&Model $tenant, ) {} diff --git a/src/Jobs/MigrateDatabase.php b/src/Jobs/MigrateDatabase.php index 424dacc9..358c4678 100644 --- a/src/Jobs/MigrateDatabase.php +++ b/src/Jobs/MigrateDatabase.php @@ -17,6 +17,8 @@ class MigrateDatabase implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public int $tries = 3; + public function __construct( protected TenantWithDatabase&Model $tenant, ) {} diff --git a/src/Jobs/SeedDatabase.php b/src/Jobs/SeedDatabase.php index 9958695e..f0c49568 100644 --- a/src/Jobs/SeedDatabase.php +++ b/src/Jobs/SeedDatabase.php @@ -17,6 +17,8 @@ class SeedDatabase implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public int $tries = 3; + public function __construct( protected TenantWithDatabase&Model $tenant, ) {}