Increase status polling interval to 5 seconds across Proxmox views; update layout styles and add new CSS for improved UI elements and animations.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Paymenter\Extensions\Servers\Proxmox\Livewire;
|
||||
|
||||
use App\Helpers\ExtensionHelper;
|
||||
use App\Livewire\Component as BaseComponent;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
|
||||
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
|
||||
|
||||
@@ -72,7 +73,7 @@ class Component extends BaseComponent
|
||||
} catch (\Throwable $e) {
|
||||
$this->notify('Action failed: ' . $e->getMessage(), 'error');
|
||||
} finally {
|
||||
$this->loadVmStatus();
|
||||
$this->forceLoadVmStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,20 +247,27 @@ class Component extends BaseComponent
|
||||
|
||||
/**
|
||||
* Refresh the cached VM status from Proxmox.
|
||||
* Cached for 5 seconds to reduce redundant API calls from polling.
|
||||
*/
|
||||
public function loadVmStatus(): void
|
||||
{
|
||||
$cacheKey = 'proxmox-vm-status-' . $this->server->id;
|
||||
|
||||
try {
|
||||
$proxmox = new Proxmox;
|
||||
$response = $proxmox->request(
|
||||
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/status/current'
|
||||
);
|
||||
|
||||
$data = $response->json()['data'] ?? null;
|
||||
$data = Cache::remember($cacheKey, 5, function () {
|
||||
$proxmox = new Proxmox;
|
||||
$response = $proxmox->request(
|
||||
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/status/current'
|
||||
);
|
||||
|
||||
return $response->json()['data'] ?? null;
|
||||
});
|
||||
|
||||
$this->status = $data ? (object) $data : null;
|
||||
} catch (\Illuminate\Http\Client\ConnectionException $e) {
|
||||
// Timeout or connection error - don't log as error, just set status to null
|
||||
\Log::info('Connection timeout loading VM status for server ' . $this->server->id);
|
||||
Cache::forget($cacheKey);
|
||||
$this->status = null;
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error('Exception loading VM status for server ' . $this->server->id, [
|
||||
@@ -268,7 +276,18 @@ class Component extends BaseComponent
|
||||
'node' => $this->server->node->name ?? 'unknown',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
Cache::forget($cacheKey);
|
||||
$this->status = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-refresh VM status by busting the cache.
|
||||
* Called after lifecycle actions (start/stop) for immediate feedback.
|
||||
*/
|
||||
public function forceLoadVmStatus(): void
|
||||
{
|
||||
Cache::forget('proxmox-vm-status-' . $this->server->id);
|
||||
$this->loadVmStatus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user