Implement VM provision locking mechanism and enhance VM job handling
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Jobs\VirtualMachine\Create;
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Jobs\VirtualMachine\Provision\AssignIpToGuestJob;
|
||||
use App\Models\OrderItem;
|
||||
use App\Models\VmProvisionLock;
|
||||
use App\Services\VirtualMachine\VmAddonResolver;
|
||||
use App\Services\VirtualMachine\VmInfrastructureResolver;
|
||||
use App\Services\VirtualMachine\VmIpReservationService;
|
||||
@@ -55,8 +56,15 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
): bool {
|
||||
$reservation = null;
|
||||
$ipPoolId = null;
|
||||
$lock = null;
|
||||
|
||||
try {
|
||||
$customerId = $this->item->order->customer_id;
|
||||
$lock = VmProvisionLock::updateOrCreate(
|
||||
['order_item_id' => $this->item->id],
|
||||
['customer_id' => $customerId, 'status' => 'running'],
|
||||
);
|
||||
|
||||
$vmLogger->step('Create VM job started', [
|
||||
'order_item_id' => $this->item->id,
|
||||
'is_retry' => $this->isRetry,
|
||||
@@ -198,12 +206,16 @@ class CreateVirtualMachineJob implements ShouldQueue
|
||||
'vm_id' => $vmId,
|
||||
]);
|
||||
|
||||
$lock?->update(['status' => 'success']);
|
||||
|
||||
return true;
|
||||
} catch (Throwable $e) {
|
||||
if ($reservation) {
|
||||
$ipReservation->release($reservation, $ipPoolId);
|
||||
}
|
||||
|
||||
$lock?->update(['status' => 'failed']);
|
||||
|
||||
$vmLogger->exception('Create VM job failed', $e, [
|
||||
'order_item_id' => $this->item->id,
|
||||
'is_retry' => $this->isRetry,
|
||||
|
||||
Reference in New Issue
Block a user