Able to add scheduled backups through the UI
This commit is contained in:
@@ -47,6 +47,9 @@ class Kernel extends ConsoleKernel
|
||||
}
|
||||
foreach ($scheduled_backups as $scheduled_backup) {
|
||||
if (!$scheduled_backup->enabled) continue;
|
||||
if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) {
|
||||
$scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency];
|
||||
}
|
||||
$schedule->job(new BackupDatabaseJob(
|
||||
backup: $scheduled_backup
|
||||
))->cron($scheduled_backup->frequency);
|
||||
|
||||
@@ -8,7 +8,7 @@ use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class ActivityMonitor extends Component
|
||||
{
|
||||
public bool $header = false;
|
||||
public string|null $header = null;
|
||||
public $activityId;
|
||||
public $isPollingActive = false;
|
||||
|
||||
|
||||
61
app/Http/Livewire/Project/Database/CreateScheduledBackup.php
Normal file
61
app/Http/Livewire/Project/Database/CreateScheduledBackup.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use App\Models\ScheduledDatabaseBackup;
|
||||
use Livewire\Component;
|
||||
use Poliander\Cron\CronExpression;
|
||||
|
||||
class CreateScheduledBackup extends Component
|
||||
{
|
||||
public $database;
|
||||
public $frequency;
|
||||
public bool $enabled = true;
|
||||
public bool $keep_locally = true;
|
||||
public bool $save_s3 = true;
|
||||
|
||||
protected $rules = [
|
||||
'frequency' => 'required|string',
|
||||
'keep_locally' => 'required|boolean',
|
||||
'save_s3' => 'required|boolean',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'frequency' => 'Backup Frequency',
|
||||
'keep_locally' => 'Keep Locally',
|
||||
'save_s3' => 'Save to S3',
|
||||
];
|
||||
|
||||
public function submit(): void
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
|
||||
$expression = new CronExpression($this->frequency);
|
||||
$isValid = $expression->isValid();
|
||||
|
||||
if (isset(VALID_CRON_STRINGS[$this->frequency])) {
|
||||
$isValid = true;
|
||||
}
|
||||
if (!$isValid) {
|
||||
$this->emit('error', 'Invalid Cron / Human expression');
|
||||
return;
|
||||
}
|
||||
ScheduledDatabaseBackup::create([
|
||||
'enabled' => true,
|
||||
'frequency' => $this->frequency,
|
||||
'keep_locally' => $this->keep_locally,
|
||||
'save_s3' => $this->save_s3,
|
||||
'database_id' => $this->database->id,
|
||||
'database_type' => $this->database->getMorphClass(),
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
]);
|
||||
$this->emit('refreshScheduledBackups');
|
||||
} catch (\Exception $e) {
|
||||
general_error_handler($e, $this);
|
||||
} finally {
|
||||
$this->frequency = '';
|
||||
$this->keep_locally = true;
|
||||
$this->save_s3 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/Http/Livewire/Project/Database/ScheduledBackups.php
Normal file
17
app/Http/Livewire/Project/Database/ScheduledBackups.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Database;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class ScheduledBackups extends Component
|
||||
{
|
||||
public $database;
|
||||
protected $listeners = ['refreshScheduledBackups'];
|
||||
|
||||
public function refreshScheduledBackups()
|
||||
{
|
||||
ray('refreshScheduledBackups');
|
||||
$this->database->refresh();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Throwable;
|
||||
|
||||
@@ -35,6 +36,16 @@ class BackupDatabaseJob implements ShouldQueue
|
||||
$this->status = $this->database->status;
|
||||
}
|
||||
|
||||
public function middleware(): array
|
||||
{
|
||||
return [new WithoutOverlapping($this->backup->id)];
|
||||
}
|
||||
|
||||
public function uniqueId(): int
|
||||
{
|
||||
return $this->backup->id;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if ($this->status !== 'running') {
|
||||
|
||||
Reference in New Issue
Block a user