Implement VM provision locking mechanism and enhance VM job handling
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Enums\Order\OrderStatus;
|
||||
use App\Helpers\OrderHelper;
|
||||
use App\Jobs\Mail\Admin\AdminOrderNotificationJob;
|
||||
use App\Jobs\VirtualMachine\Create\CreateVirtualMachineJob;
|
||||
use App\Models\VmProvisionLock;
|
||||
use App\Models\Addon;
|
||||
use App\Models\Log as CustomerActivityLog;
|
||||
use App\Models\Order;
|
||||
@@ -224,6 +225,14 @@ class OrderService
|
||||
private function dispatchVmJob(Order $order, OrderItem $item, Service $service, $customer): void
|
||||
{
|
||||
try {
|
||||
if (VmProvisionLock::isRunning($customer->id)) {
|
||||
Log::warning('dispatchVmJob: blocked — customer already has a running VM provision', [
|
||||
'customer_id' => $customer->id,
|
||||
'order_item_id' => $item->id,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(new CreateVirtualMachineJob($item));
|
||||
|
||||
Log::info('dispatchVmJob: CreateVirtualMachineJob dispatched', [
|
||||
|
||||
@@ -24,7 +24,9 @@ class VmIpReservationService
|
||||
public function reserve(int $networkId, int $hostId, string $dns): ?array
|
||||
{
|
||||
return DB::transaction(function () use ($networkId, $hostId, $dns) {
|
||||
// ponytail: exclude only IPs with an actual VM assigned, not stale __pending__ reservations
|
||||
$usedIps = ModuleIpAddress::where('module_network_id', $networkId)
|
||||
->where('vm_name', '!=', '__pending__')
|
||||
->lockForUpdate()
|
||||
->pluck('ip')
|
||||
->toArray();
|
||||
|
||||
Reference in New Issue
Block a user