mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 16:52:45 -04:00
- database import: add keep_owners (restore PostgreSQL owners and privileges) and sqlite_database (pick the target SQLite file) to the API, OpenAPI spec, and import form - oauth: require password confirmation and support team selection on OAuth login - remote process: send team broadcast events to the team of the server that ran the process instead of the causer's user id - servers API: handle the legacy build server setting - compose: support parent bind paths and volume driver options - dns: improve record hints and provider management - notifications: fix throttling and missing backup notifications - ui: rework the confirmation modal - add feature and unit tests for the new behavior
62 lines
2.0 KiB
PHP
62 lines
2.0 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 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;
|
|
}
|
|
|
|
// Send once for each period without backup activity.
|
|
NotificationThrottle::sendOnce(
|
|
$backup,
|
|
BackupMissing::class,
|
|
$lastActivityAt,
|
|
fn () => $backup->team->notify(new BackupMissing($backup, $lastExecutionAt)),
|
|
);
|
|
}
|
|
}
|