refactor(proxy): streamline proxy status handling and improve dashboard availability checks

This commit is contained in:
Andras Bacsai
2025-06-11 12:02:39 +02:00
parent 23d5ada3b8
commit 9ad2304229
20 changed files with 459 additions and 559 deletions

View File

@@ -22,11 +22,14 @@ class Navbar extends Component
public ?string $serverIp = null;
public ?string $proxyStatus = 'unknown';
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
return [
'refreshServerShow' => '$refresh',
"echo-private:team.{$teamId},ProxyStatusChangedUI" => 'showNotification',
];
}
@@ -36,13 +39,16 @@ class Navbar extends Component
$this->server = $server;
$this->currentRoute = request()->route()->getName();
$this->serverIp = $this->server->id === 0 ? base_ip() : $this->server->ip;
$this->proxyStatus = $this->server->proxy->status ?? 'unknown';
$this->loadProxyConfiguration();
}
public function loadProxyConfiguration()
{
try {
$this->traefikDashboardAvailable = ProxyDashboardCacheService::isTraefikDashboardAvailable($this->server);
if ($this->proxyStatus === 'running') {
$this->traefikDashboardAvailable = ProxyDashboardCacheService::isTraefikDashboardAvailableFromCache($this->server);
}
} catch (\Throwable $e) {
return handleError($e, $this);
}
@@ -51,8 +57,6 @@ class Navbar extends Component
public function restart()
{
try {
// Clear cache before restarting proxy
ProxyDashboardCacheService::clearCache($this->server);
RestartProxyJob::dispatch($this->server);
} catch (\Throwable $e) {
return handleError($e, $this);
@@ -97,37 +101,42 @@ class Navbar extends Component
try {
$this->isChecking = true;
CheckProxy::run($this->server, true);
$this->showNotification();
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
$this->isChecking = false;
$this->showNotification();
}
}
public function showNotification()
{
$status = $this->server->proxy->status ?? 'unknown';
$this->proxyStatus = $this->server->proxy->status ?? 'unknown';
$forceStop = $this->server->proxy->force_stop ?? false;
switch ($status) {
switch ($this->proxyStatus) {
case 'running':
$this->dispatch('success', 'Proxy is running.');
// $this->dispatch('success', 'Proxy is running.');
$this->loadProxyConfiguration();
break;
case 'restarting':
$this->dispatch('info', 'Initiating proxy restart.');
break;
case 'exited':
if ($forceStop) {
$this->dispatch('info', 'Proxy is stopped manually.');
} else {
$this->dispatch('info', 'Proxy is stopped manually.<br>Starting in a moment.');
}
// case 'exited':
// if (! $forceStop) {
// $this->dispatch('info', 'Proxy is stopped manually.<br>Starting in a moment.');
// }
// break;
case 'starting':
// do nothing
break;
case 'stopping':
// do nothing
break;
default:
$this->dispatch('warning', 'Proxy is not running.');
break;
}
}
public function render()

View File

@@ -5,7 +5,6 @@ namespace App\Livewire\Server;
use App\Actions\Proxy\CheckConfiguration;
use App\Actions\Proxy\SaveConfiguration;
use App\Models\Server;
use App\Services\ProxyDashboardCacheService;
use Livewire\Component;
class Proxy extends Component
@@ -43,9 +42,6 @@ class Proxy extends Component
$this->server->proxy = null;
$this->server->save();
// Clear Traefik dashboard cache when proxy type changes
ProxyDashboardCacheService::clearCache($this->server);
$this->dispatch('reloadWindow');
}
@@ -55,9 +51,6 @@ class Proxy extends Component
$this->server->changeProxy($proxy_type, async: false);
$this->selectedProxy = $this->server->proxy->type;
// Clear Traefik dashboard cache when proxy type is selected
ProxyDashboardCacheService::clearCache($this->server);
$this->dispatch('reloadWindow');
} catch (\Throwable $e) {
return handleError($e, $this);

View File

@@ -184,7 +184,6 @@ class Show extends Component
public function refresh()
{
$this->syncData();
$this->dispatch('$refresh');
}
public function validateServer($install = true)

View File

@@ -2,6 +2,8 @@
namespace App\Livewire\Server;
use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Livewire\Component;
@@ -25,8 +27,6 @@ class ValidateAndInstall extends Component
public $docker_version = null;
public $proxy_started = false;
public $error = null;
public bool $ask = false;
@@ -47,7 +47,6 @@ class ValidateAndInstall extends Component
$this->docker_installed = null;
$this->docker_version = null;
$this->docker_compose_installed = null;
$this->proxy_started = null;
$this->error = null;
$this->number_of_tries = $data;
if (! $this->ask) {
@@ -135,7 +134,12 @@ class ValidateAndInstall extends Component
if ($this->docker_version) {
$this->dispatch('refreshServerShow');
$this->dispatch('refreshBoardingIndex');
$this->dispatch('success', 'Server validated.');
$this->dispatch('success', 'Server validated, proxy is starting in a moment.');
$proxyShouldRun = CheckProxy::run($this->server, true);
if (! $proxyShouldRun) {
return;
}
StartProxy::dispatch($this->server);
} else {
$requiredDockerVersion = str(config('constants.docker.minimum_required_version'))->before('.');
$this->error = 'Minimum Docker Engine version '.$requiredDockerVersion.' is not instaled. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';