update
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs\VirtualMachine\Rebuild;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Jobs\Mail\Customer\VmRebuildFailedJob;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\ReinstallLog;
|
||||
use App\Models\Service;
|
||||
@@ -39,6 +41,8 @@ final class RebuildVirtualMachineJob implements ShouldQueue
|
||||
public int $tries = 1;
|
||||
public int $timeout = 900;
|
||||
|
||||
private bool $failureHandled = false;
|
||||
|
||||
public function __construct(
|
||||
public readonly int $moduleVmwareId,
|
||||
public readonly int $newOsId,
|
||||
@@ -85,6 +89,8 @@ final class RebuildVirtualMachineJob implements ShouldQueue
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
'new_vm_id' => $newVmId,
|
||||
]);
|
||||
|
||||
(new Telegram)->SendRebuildStepNotification($ctx->vmName, $ctx->ip, 'Clone VM mới', true);
|
||||
} catch (Throwable $e) {
|
||||
$this->onFailure($e);
|
||||
throw $e;
|
||||
@@ -98,6 +104,11 @@ final class RebuildVirtualMachineJob implements ShouldQueue
|
||||
|
||||
private function onFailure(Throwable $e): void
|
||||
{
|
||||
if ($this->failureHandled) {
|
||||
return;
|
||||
}
|
||||
$this->failureHandled = true;
|
||||
|
||||
Log::error('RebuildVirtualMachineJob: failed — old VM preserved', [
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
'error' => $e->getMessage(),
|
||||
@@ -113,6 +124,23 @@ final class RebuildVirtualMachineJob implements ShouldQueue
|
||||
'status' => ReinstallLog::STATUS_FAILED,
|
||||
'error_message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::with('customer')->find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Clone VM mới',
|
||||
false,
|
||||
$e->getMessage(),
|
||||
);
|
||||
|
||||
VmRebuildFailedJob::dispatch([
|
||||
'customer_email' => $vm?->customer?->email,
|
||||
'customer_name' => $vm?->customer?->fullname,
|
||||
'vm_name' => $vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
'ip' => $vm->ip ?? '',
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
]);
|
||||
}
|
||||
|
||||
private function markServiceStatus(?int $serviceId, string $status): void
|
||||
|
||||
Reference in New Issue
Block a user