57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\VirtualMachine\Handle;
|
|
|
|
use App\Events\VirtualMachine_Panel_Status;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Console\Scheduling\Event;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class WaitStatusVirtualMachine implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected string $vmware_id;
|
|
protected $serviceVCetner;
|
|
protected bool $status;
|
|
protected int $user;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($vmware_id,$service,$user,$status)
|
|
{
|
|
//
|
|
$this->vmware_id = $vmware_id;
|
|
$this->serviceVCetner = $service;
|
|
$this->user = $user;
|
|
$this->status = $status;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$status = $this->serviceVCetner->CheckVirtualMachine($this->vmware_id);
|
|
|
|
if ($status['error'] === true) {
|
|
throw new \Exception(json_encode($status['message']));
|
|
}
|
|
if ($status['data']['operations_ready'] === $this->status) {
|
|
do {
|
|
sleep(10);
|
|
$status = $this->serviceVCetner->CheckVirtualMachine($this->vmware_id);
|
|
} while ($status['data']['operations_ready'] === $this->status);
|
|
}
|
|
|
|
Event(new VirtualMachine_Panel_Status('Yêu cầu được xử lý thành công',$this->user));
|
|
}
|
|
}
|