mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-21 23:20:24 +00:00
update
This commit is contained in:
parent
f81cf44978
commit
4320aa029c
3 changed files with 69 additions and 44 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Jobs\ProcessHostingSubscriptionBackup;
|
use App\Jobs\CreateHostingSubscriptionBackup;
|
||||||
use App\Models\Backup;
|
use App\Models\Backup;
|
||||||
use App\Models\HostingSubscription;
|
use App\Models\HostingSubscription;
|
||||||
use App\Models\HostingSubscriptionBackup;
|
use App\Models\HostingSubscriptionBackup;
|
||||||
|
@ -46,9 +46,7 @@ class CreateDailyFullHostingSubscriptionsBackup extends Command
|
||||||
->where('created_at', '>=', Carbon::now()->subHours(24))
|
->where('created_at', '>=', Carbon::now()->subHours(24))
|
||||||
->first();
|
->first();
|
||||||
if (! $findBackup) {
|
if (! $findBackup) {
|
||||||
|
CreateHostingSubscriptionBackup::dispatch($hostingSubscription->id);
|
||||||
ProcessHostingSubscriptionBackup::dispatch($hostingSubscription->id);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->error('Backup already exists for ' . $hostingSubscription->domain);
|
$this->error('Backup already exists for ' . $hostingSubscription->domain);
|
||||||
$this->error('Created before: ' . $findBackup->created_at->diffForHumans());
|
$this->error('Created before: ' . $findBackup->created_at->diffForHumans());
|
||||||
|
|
67
web/app/Jobs/CreateHostingSubscriptionBackup.php
Normal file
67
web/app/Jobs/CreateHostingSubscriptionBackup.php
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Filament\Enums\BackupStatus;
|
||||||
|
use App\Models\HostingSubscription;
|
||||||
|
use App\Models\HostingSubscriptionBackup;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class CreateHostingSubscriptionBackup implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
protected $hostingSubscriptionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct($hostingSubscriptionId)
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\HostingSubscriptionBackup;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class ProcessHostingSubscriptionBackup implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
protected $hostingSubscriptionId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct($hostingSubscriptionId)
|
|
||||||
{
|
|
||||||
$this->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();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue