update
This commit is contained in:
@@ -4,6 +4,9 @@ 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\Services\VirtualMachine\Rebuild\VmRebuildAddonService;
|
||||
use App\Services\VirtualMachine\Rebuild\VmRebuildService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -62,6 +65,8 @@ final class RebuildAddonInstallJob implements ShouldQueue
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
'new_vm_id' => $this->newVmId,
|
||||
]);
|
||||
|
||||
(new Telegram)->SendRebuildStepNotification($ctx->vmName, $ctx->ip, 'Cài đặt addon (CPU/RAM/Disk)', true);
|
||||
}
|
||||
|
||||
public function failed(Throwable $e): void
|
||||
@@ -77,5 +82,22 @@ final class RebuildAddonInstallJob implements ShouldQueue
|
||||
'error_message' => 'AddonInstall failed: ' . $e->getMessage(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::with('customer')->find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Cài đặt addon (CPU/RAM/Disk)',
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ 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\Services\VirtualMachine\Rebuild\VmRebuildIpService;
|
||||
use App\Services\VirtualMachine\Rebuild\VmRebuildService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -73,6 +76,8 @@ final class RebuildAssignIpJob implements ShouldQueue
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
'new_vm_id' => $this->newVmId,
|
||||
]);
|
||||
|
||||
(new Telegram)->SendRebuildStepNotification($ctx->vmName, $ctx->ip, 'Gán địa chỉ IP', true);
|
||||
}
|
||||
|
||||
public function failed(Throwable $e): void
|
||||
@@ -88,5 +93,22 @@ final class RebuildAssignIpJob implements ShouldQueue
|
||||
'error_message' => 'AssignIp failed: ' . $e->getMessage(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::with('customer')->find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Gán địa chỉ IP',
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ 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\Services\VirtualMachine\Rebuild\VmRebuildPasswordService;
|
||||
use App\Services\VirtualMachine\Rebuild\VmRebuildService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -62,6 +65,15 @@ final class RebuildChangePasswordJob implements ShouldQueue
|
||||
'module_vmware_id' => $this->moduleVmwareId,
|
||||
'new_vm_id' => $this->newVmId,
|
||||
]);
|
||||
|
||||
$vmAfter = ModuleVmware::find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$ctx->vmName,
|
||||
$ctx->ip,
|
||||
'Đổi mật khẩu' . ($ctx->isWindows ? ' & Port RDP' : ''),
|
||||
true,
|
||||
$ctx->isWindows ? "Port RDP mới: {$vmAfter?->port}" : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(Throwable $e): void
|
||||
@@ -77,5 +89,22 @@ final class RebuildChangePasswordJob implements ShouldQueue
|
||||
'error_message' => 'ChangePassword failed: ' . $e->getMessage(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::with('customer')->find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Đổi mật khẩu & Port',
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs\VirtualMachine\Rebuild;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Http\Services\vCenter as VCenterService;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\vCenter as VCenterModel;
|
||||
@@ -82,6 +83,8 @@ final class RebuildDeleteOldVmJob implements ShouldQueue
|
||||
'old_vm_id' => $this->oldVmId,
|
||||
'result' => $res,
|
||||
]);
|
||||
|
||||
(new Telegram)->SendRebuildStepNotification($vm->name ?? '', $vm->ip ?? '', 'Xoá VM cũ', true);
|
||||
} catch (Throwable $e) {
|
||||
Log::error('RebuildDeleteOldVmJob: delete failed', [
|
||||
'old_vm_id' => $this->oldVmId,
|
||||
@@ -99,5 +102,14 @@ final class RebuildDeleteOldVmJob implements ShouldQueue
|
||||
'old_vm_id' => $this->oldVmId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Xoá VM cũ',
|
||||
false,
|
||||
"Old VM {$this->oldVmId} cần xoá thủ công: " . $e->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs\VirtualMachine\Rebuild;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Jobs\Mail\Admin\AdminOrderNotificationJob;
|
||||
use App\Jobs\Mail\Customer\VmRebuildFailedJob;
|
||||
use App\Jobs\Mail\SendInformationVirtualMachine;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\ModuleVmware;
|
||||
@@ -94,6 +96,8 @@ final class RebuildFinalizeJob implements ShouldQueue
|
||||
'new_vm_id' => $this->newVmId,
|
||||
'old_vm_id' => $oldVmId,
|
||||
]);
|
||||
|
||||
(new Telegram)->SendRebuildStepNotification($ctx->vmName, $ctx->ip, 'Hoàn tất & chuyển đổi VM', true, 'Rebuild thành công, VM mới đã online.');
|
||||
}
|
||||
|
||||
public function failed(Throwable $e): void
|
||||
@@ -109,6 +113,23 @@ final class RebuildFinalizeJob implements ShouldQueue
|
||||
'error_message' => $e->getMessage(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$vm = ModuleVmware::with('customer')->find($this->moduleVmwareId);
|
||||
(new Telegram)->SendRebuildStepNotification(
|
||||
$vm->name ?? "VM #{$this->moduleVmwareId}",
|
||||
$vm->ip ?? '',
|
||||
'Hoàn tất & chuyển đổi VM',
|
||||
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 sendCredentialsEmail(int $moduleVmwareId): void
|
||||
|
||||
@@ -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