mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
- Skip TrimStrings and ConvertEmptyStringsToNull on the import route; an empty shared variable failed the whole import - Keep compose parser versions, static ports, legacy variable keys, and only the bundle's variables and destinations - Give the transfer back token the deploy permission that the import needs - Move the Cloudflare tunnel DNS record with the server and park it on the source - Refuse cloud server deletes, power on, tunnel and DNS changes, and scp for archives; skip their backup alerts and provider polling - Add a column-level round-trip test, archive guard tests, and a live full-coverage transfer test - Advance the GitLab App sequence in the dev seeder
75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\NotificationThrottle;
|
|
use App\Models\ScheduledDatabaseBackup;
|
|
use App\Notifications\Database\BackupMissing;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CheckMissingDatabaseBackupsJob implements ShouldBeEncrypted, ShouldBeUnique, ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $timeout = 1800;
|
|
|
|
/**
|
|
* Releases the unique lock of a killed worker after one run (the timeout), so the next hourly run is not
|
|
* blocked until the queue retry_after.
|
|
*/
|
|
public int $uniqueFor = 1800;
|
|
|
|
public function handle(): void
|
|
{
|
|
ScheduledDatabaseBackup::query()
|
|
->with(['team', 'database', 'latest_log'])
|
|
->where('enabled', true)
|
|
->where('missing_backup_notification_days', '>', 0)
|
|
->chunkById(100, function ($backups): void {
|
|
foreach ($backups as $backup) {
|
|
$this->notifyIfMissing($backup);
|
|
}
|
|
});
|
|
}
|
|
|
|
private function notifyIfMissing(ScheduledDatabaseBackup $backup): void
|
|
{
|
|
$lastExecutionAt = $backup->last_execution_at ?? $backup->latest_log?->created_at;
|
|
$lastActivityAt = $lastExecutionAt ?? $backup->created_at;
|
|
|
|
if (! $lastActivityAt || $lastActivityAt->isAfter(now()->subDays($backup->missing_backup_notification_days))) {
|
|
return;
|
|
}
|
|
|
|
if (! $backup->team) {
|
|
Log::warning("Cannot send missing backup notification for backup {$backup->id}: team not found");
|
|
|
|
return;
|
|
}
|
|
|
|
if ($backup->team->getEnabledChannels('backup_failure') === []) {
|
|
return;
|
|
}
|
|
|
|
// Another Coolify instance backs up the databases of a transferred server.
|
|
if ($backup->server()?->isTransferredAway()) {
|
|
return;
|
|
}
|
|
|
|
// Send once for each period without backup activity.
|
|
NotificationThrottle::sendOnce(
|
|
$backup,
|
|
BackupMissing::class,
|
|
$lastActivityAt,
|
|
fn () => $backup->team->notify(new BackupMissing($backup, $lastExecutionAt)),
|
|
);
|
|
}
|
|
}
|