From 4320aa029cde9e25d74c0ec0eda25aa2b9d96810 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 7 May 2024 15:42:17 +0300 Subject: [PATCH] update --- ...ateDailyFullHostingSubscriptionsBackup.php | 6 +- .../Jobs/CreateHostingSubscriptionBackup.php | 67 +++++++++++++++++++ .../Jobs/ProcessHostingSubscriptionBackup.php | 40 ----------- 3 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 web/app/Jobs/CreateHostingSubscriptionBackup.php delete mode 100644 web/app/Jobs/ProcessHostingSubscriptionBackup.php diff --git a/web/app/Console/Commands/CreateDailyFullHostingSubscriptionsBackup.php b/web/app/Console/Commands/CreateDailyFullHostingSubscriptionsBackup.php index 8e5a2fa..2b699ba 100644 --- a/web/app/Console/Commands/CreateDailyFullHostingSubscriptionsBackup.php +++ b/web/app/Console/Commands/CreateDailyFullHostingSubscriptionsBackup.php @@ -2,7 +2,7 @@ namespace App\Console\Commands; -use App\Jobs\ProcessHostingSubscriptionBackup; +use App\Jobs\CreateHostingSubscriptionBackup; use App\Models\Backup; use App\Models\HostingSubscription; use App\Models\HostingSubscriptionBackup; @@ -46,9 +46,7 @@ class CreateDailyFullHostingSubscriptionsBackup extends Command ->where('created_at', '>=', Carbon::now()->subHours(24)) ->first(); if (! $findBackup) { - - ProcessHostingSubscriptionBackup::dispatch($hostingSubscription->id); - + CreateHostingSubscriptionBackup::dispatch($hostingSubscription->id); } else { $this->error('Backup already exists for ' . $hostingSubscription->domain); $this->error('Created before: ' . $findBackup->created_at->diffForHumans()); diff --git a/web/app/Jobs/CreateHostingSubscriptionBackup.php b/web/app/Jobs/CreateHostingSubscriptionBackup.php new file mode 100644 index 0000000..7e0d8c3 --- /dev/null +++ b/web/app/Jobs/CreateHostingSubscriptionBackup.php @@ -0,0 +1,67 @@ +hostingSubscriptionId = $hostingSubscriptionId; + } + + /** + * Execute the job. + */ + public function handle(): void + { + echo "Backup hosting subscription with ID: {$this->hostingSubscriptionId}\n"; + + $backup = new HostingSubscriptionBackup(); + $backup->hosting_subscription_id = $this->hostingSubscriptionId; + $backup->backup_type = 'full'; + $backup->save(); + + $backupDone = false; + $findHostingSubscriptionBackup = HostingSubscriptionBackup::where('id', $backup->id)->first(); + if ($findHostingSubscriptionBackup) { + + for ($i = 0; $i < 200; $i++) { + echo "Check: ".$i." | Checking backup status...\n"; + $findHostingSubscriptionBackup->checkBackup(); + if ($findHostingSubscriptionBackup->status == BackupStatus::Completed) { + echo "Backup completed\n"; + $backupDone = true; + break; + } + + sleep(4); + } + + if (! $backupDone) { + echo "Backup failed\n"; + $findHostingSubscriptionBackup->status = BackupStatus::Failed; + $findHostingSubscriptionBackup->save(); + } + } + + + } + + +} diff --git a/web/app/Jobs/ProcessHostingSubscriptionBackup.php b/web/app/Jobs/ProcessHostingSubscriptionBackup.php deleted file mode 100644 index be2dcb2..0000000 --- a/web/app/Jobs/ProcessHostingSubscriptionBackup.php +++ /dev/null @@ -1,40 +0,0 @@ -hostingSubscriptionId = $hostingSubscriptionId; - } - - /** - * Execute the job. - */ - public function handle(): void - { - echo "Backing up hosting subscription with ID: {$this->hostingSubscriptionId}\n"; - - sleep(3); -// -// $backup = new HostingSubscriptionBackup(); -// $backup->hosting_subscription_id = $this->hostingSubscriptionId; -// $backup->backup_type = 'full'; -// $backup->save(); - } -}