feat(databases): implement unique UUID generation for backup execution

- Enhanced the DatabaseBackupJob to generate a unique UUID for each backup execution attempt.
- Added logic to retry UUID generation up to three times if a duplicate is detected, ensuring uniqueness and preventing execution conflicts.
This commit is contained in:
Andras Bacsai
2025-09-23 09:13:10 +02:00
parent dc32bed1ae
commit 99b101507c

View File

@@ -74,13 +74,21 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
{
$this->onQueue('high');
$this->timeout = $backup->timeout;
$this->backup_log_uuid = (string) new Cuid2;
}
public function handle(): void
{
try {
$attempts = 0;
do {
$this->backup_log_uuid = (string) new Cuid2;
$exists = ScheduledDatabaseBackupExecution::where('uuid', $this->backup_log_uuid)->exists();
$attempts++;
if ($attempts >= 3 && $exists) {
throw new \Exception('Unable to generate unique UUID for backup execution after 3 attempts');
}
} while ($exists);
$databasesToBackup = null;
$this->team = Team::find($this->backup->team_id);