feat: enhance VM status loading with retry logic and improved error handling
This commit is contained in:
@@ -4,17 +4,30 @@ namespace Paymenter\Extensions\Servers\Proxmox\Livewire;
|
||||
|
||||
use Paymenter\Extensions\Servers\Proxmox\Models\Server as ServerModel;
|
||||
use Paymenter\Extensions\Servers\Proxmox\Models\ServerStatistics;
|
||||
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Server extends Component
|
||||
{
|
||||
protected int $maxRetries = 3;
|
||||
|
||||
public function mount(ServerModel $server): void
|
||||
{
|
||||
parent::mount($server);
|
||||
|
||||
// Check and enforce bandwidth throttling if exceeded
|
||||
$this->checkAndEnforceBandwidthLimit();
|
||||
// Retry loading VM status if initial load failed
|
||||
$retries = 0;
|
||||
while ($this->status === null && $retries < $this->maxRetries) {
|
||||
usleep(100000); // 100ms delay between retries
|
||||
$this->loadVmStatus();
|
||||
$retries++;
|
||||
}
|
||||
|
||||
// Check and enforce bandwidth throttling if exceeded (only if status loaded)
|
||||
if ($this->status !== null) {
|
||||
$this->checkAndEnforceBandwidthLimit();
|
||||
}
|
||||
}
|
||||
|
||||
public function getMonthlyTrafficProperty()
|
||||
@@ -162,6 +175,18 @@ class Server extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function retryLoadStatus(): void
|
||||
{
|
||||
$retries = 0;
|
||||
while ($this->status === null && $retries < $this->maxRetries) {
|
||||
$this->loadVmStatus();
|
||||
if ($this->status === null) {
|
||||
usleep(200000); // 200ms delay between retries
|
||||
}
|
||||
$retries++;
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('proxmox::server');
|
||||
|
||||
Reference in New Issue
Block a user