Files
portal-api/app/Jobs/VirtualMachine/Create/CheckStatusVirtualMachine.php
T
2025-07-24 16:18:27 +07:00

55 lines
1.4 KiB
PHP

<?php
namespace App\Jobs\VirtualMachine\Create;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CheckStatusVirtualMachine implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $vmware_id;
protected $serviceVCenter;
protected $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($vmware_id, $data,$service)
{
$this->vmware_id = $vmware_id;
$this->serviceVCenter = $service;
$this->data = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$status = $this->serviceVCenter->CheckVirtualMachine($this->vmware_id);
if ($status['error'] === true) {
throw new \Exception(json_encode($status['message']));
}
if ($status['data']['operations_ready'] === false) {
do {
sleep(10);
$status = $this->serviceVCenter->CheckVirtualMachine($this->vmware_id);
} while ($status['data']['operations_ready'] !== true);
}
$jobs_configNetwork = new GetNetworkVirtualMachine($this->vmware_id,$this->data,$this->serviceVCenter);
dispatch($jobs_configNetwork)->delay(now()->addSeconds(5));
}
}