fix: improve server list reliability with async retry polling instead of blocking usleep
This commit is contained in:
@@ -11,18 +11,12 @@ use Illuminate\Support\Facades\Cache;
|
|||||||
class Server extends Component
|
class Server extends Component
|
||||||
{
|
{
|
||||||
protected int $maxRetries = 3;
|
protected int $maxRetries = 3;
|
||||||
|
public int $loadAttempts = 0;
|
||||||
|
|
||||||
public function mount(ServerModel $server): void
|
public function mount(ServerModel $server): void
|
||||||
{
|
{
|
||||||
parent::mount($server);
|
parent::mount($server);
|
||||||
|
$this->loadAttempts = 1;
|
||||||
// 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)
|
// Check and enforce bandwidth throttling if exceeded (only if status loaded)
|
||||||
if ($this->status !== null) {
|
if ($this->status !== null) {
|
||||||
@@ -177,13 +171,28 @@ class Server extends Component
|
|||||||
|
|
||||||
public function retryLoadStatus(): void
|
public function retryLoadStatus(): void
|
||||||
{
|
{
|
||||||
$retries = 0;
|
$this->loadAttempts++;
|
||||||
while ($this->status === null && $retries < $this->maxRetries) {
|
$this->loadVmStatus();
|
||||||
|
|
||||||
|
// Check bandwidth throttling on successful load
|
||||||
|
if ($this->status !== null) {
|
||||||
|
$this->checkAndEnforceBandwidthLimit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-retry loading status via polling (called by wire:poll when status is null)
|
||||||
|
*/
|
||||||
|
public function autoRetryLoadStatus(): void
|
||||||
|
{
|
||||||
|
if ($this->status === null && $this->loadAttempts < $this->maxRetries) {
|
||||||
|
$this->loadAttempts++;
|
||||||
$this->loadVmStatus();
|
$this->loadVmStatus();
|
||||||
if ($this->status === null) {
|
|
||||||
usleep(200000); // 200ms delay between retries
|
// Check bandwidth throttling on successful load
|
||||||
|
if ($this->status !== null) {
|
||||||
|
$this->checkAndEnforceBandwidthLimit();
|
||||||
}
|
}
|
||||||
$retries++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<div class="space-y-4">
|
<div class="space-y-4" @if(!$status && $loadAttempts < 3) wire:poll.500ms="autoRetryLoadStatus" @endif>
|
||||||
@if(!$status)
|
@if(!$status)
|
||||||
{{-- Show loading placeholder if status is not yet loaded --}}
|
{{-- Show loading placeholder if status is not yet loaded --}}
|
||||||
<div class="bg-background-secondary border border-neutral p-4 rounded-lg mb-4 flex flex-col">
|
<div class="bg-background-secondary border border-neutral p-4 rounded-lg mb-4 flex flex-col">
|
||||||
@@ -13,7 +13,13 @@
|
|||||||
<div class="size-5">
|
<div class="size-5">
|
||||||
<x-ri-loader-4-line class="animate-spin" />
|
<x-ri-loader-4-line class="animate-spin" />
|
||||||
</div>
|
</div>
|
||||||
<span class="text-sm font-medium">Loading...</span>
|
<span class="text-sm font-medium">
|
||||||
|
@if($loadAttempts < 3)
|
||||||
|
Loading... ({{ $loadAttempts }}/3)
|
||||||
|
@else
|
||||||
|
Failed to load
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row flex-wrap gap-4 mt-4">
|
<div class="flex flex-row flex-wrap gap-4 mt-4">
|
||||||
@@ -26,9 +32,11 @@
|
|||||||
<span class="text-base">{{ $server->primaryIpv6->ip ?? 'None' }}</span>
|
<span class="text-base">{{ $server->primaryIpv6->ip ?? 'None' }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4 pt-4 border-t border-neutral">
|
@if($loadAttempts >= 3)
|
||||||
<div class="text-sm text-base/50">Unable to fetch server status from Proxmox. <button wire:click="retryLoadStatus" class="text-primary hover:underline">Retry</button></div>
|
<div class="mt-4 pt-4 border-t border-neutral">
|
||||||
</div>
|
<div class="text-sm text-base/50">Unable to fetch server status from Proxmox. <button wire:click="retryLoadStatus" class="text-primary hover:underline">Retry</button></div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
<a href="{{ route('proxmox.server.overview', ['server' => $server->id]) }}" wire:navigate>
|
<a href="{{ route('proxmox.server.overview', ['server' => $server->id]) }}" wire:navigate>
|
||||||
|
|||||||
Reference in New Issue
Block a user