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

78 lines
2.1 KiB
PHP

<?php
namespace App\Jobs\VirtualMachine\Upgrade;
use App\Http\Services\Telegram;
use App\Http\Services\vCenter as ServiceVCenter;
use App\Jobs\Throwable;
use App\Models\ModuleVmware;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UpgradeCPU implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected int $cpu;
protected int $product = 0;
protected $telegram;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($product = 0, $cpu = 0)
{
$this->cpu = $cpu;
$this->product = $product;
$this->telegram = new Telegram;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(ServiceVCenter $serviceVCenter)
{
$product = ModuleVmware::with([
'IpAddress.Host.Datacenter.vCenter'
])->find($this->product);
$serviceVCenter->token = $product->IpAddress->Host->Datacenter->vCenter->token;
$serviceVCenter->apiUri = $product->IpAddress->Host->Datacenter->vCenter->host;
$StatusVirtualMachine = $serviceVCenter->UpgradeCPUVirtualMachine($product->vmware_id, $this->cpu);
if ($StatusVirtualMachine === "Login_Again") {
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
if ($token) {
$product->IpAddress->Host->Datacenter->vCenter->update(['token' => $token]);
$serviceVCenter->token = $token;
}
$StatusVirtualMachine = $serviceVCenter->UpgradeCPUVirtualMachine($product->vmware_id, $this->cpu);
}
if ($StatusVirtualMachine['error']) {
throw new Exception(json_encode($StatusVirtualMachine['data']));
}
}
public function failed(Throwable $exception)
{
$this->telegram->SendErrorMessage($exception->getMessage());
}
}