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
|
||||
{
|
||||
protected int $maxRetries = 3;
|
||||
public int $loadAttempts = 0;
|
||||
|
||||
public function mount(ServerModel $server): void
|
||||
{
|
||||
parent::mount($server);
|
||||
|
||||
// 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++;
|
||||
}
|
||||
$this->loadAttempts = 1;
|
||||
|
||||
// Check and enforce bandwidth throttling if exceeded (only if status loaded)
|
||||
if ($this->status !== null) {
|
||||
@@ -177,13 +171,28 @@ class Server extends Component
|
||||
|
||||
public function retryLoadStatus(): void
|
||||
{
|
||||
$retries = 0;
|
||||
while ($this->status === null && $retries < $this->maxRetries) {
|
||||
$this->loadAttempts++;
|
||||
$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();
|
||||
if ($this->status === null) {
|
||||
usleep(200000); // 200ms delay between retries
|
||||
|
||||
// Check bandwidth throttling on successful load
|
||||
if ($this->status !== null) {
|
||||
$this->checkAndEnforceBandwidthLimit();
|
||||
}
|
||||
$retries++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user