mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-19 18:15:31 +00:00
Run proxy restart as background job with real-time logs (#7475)
This commit is contained in:
6 files changed
+378
-18
No files matched your search
@@ -6,6 +6,7 @@ use App\Actions\Proxy\CheckProxy;
|
||||
use App\Actions\Proxy\StartProxy;
|
||||
use App\Actions\Proxy\StopProxy;
|
||||
use App\Enums\ProxyTypes;
|
||||
use App\Jobs\RestartProxyJob;
|
||||
use App\Models\Server;
|
||||
use App\Services\ProxyDashboardCacheService;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
@@ -27,6 +28,10 @@ class Navbar extends Component
|
||||
|
||||
public ?string $proxyStatus = 'unknown';
|
||||
|
||||
public ?string $lastNotifiedStatus = null;
|
||||
|
||||
public bool $restartInitiated = false;
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
$teamId = auth()->user()->currentTeam()->id;
|
||||
@@ -61,14 +66,19 @@ class Navbar extends Component
|
||||
{
|
||||
try {
|
||||
$this->authorize('manageProxy', $this->server);
|
||||
StopProxy::run($this->server, restarting: true);
|
||||
|
||||
$this->server->proxy->force_stop = false;
|
||||
$this->server->save();
|
||||
// Prevent duplicate restart calls
|
||||
if ($this->restartInitiated) {
|
||||
return;
|
||||
}
|
||||
$this->restartInitiated = true;
|
||||
|
||||
// Always use background job for all servers
|
||||
RestartProxyJob::dispatch($this->server);
|
||||
|
||||
$activity = StartProxy::run($this->server, force: true, restarting: true);
|
||||
$this->dispatch('activityMonitor', $activity->id);
|
||||
} catch (\Throwable $e) {
|
||||
$this->restartInitiated = false;
|
||||
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
@@ -122,12 +132,27 @@ class Navbar extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function showNotification()
|
||||
public function showNotification($event = null)
|
||||
{
|
||||
$previousStatus = $this->proxyStatus;
|
||||
$this->server->refresh();
|
||||
$this->proxyStatus = $this->server->proxy->status ?? 'unknown';
|
||||
|
||||
// If event contains activityId, open activity monitor
|
||||
if ($event && isset($event['activityId'])) {
|
||||
$this->dispatch('activityMonitor', $event['activityId']);
|
||||
}
|
||||
|
||||
// Reset restart flag when proxy reaches a stable state
|
||||
if (in_array($this->proxyStatus, ['running', 'exited', 'error'])) {
|
||||
$this->restartInitiated = false;
|
||||
}
|
||||
|
||||
// Skip notification if we already notified about this status (prevents duplicates)
|
||||
if ($this->lastNotifiedStatus === $this->proxyStatus) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->proxyStatus) {
|
||||
case 'running':
|
||||
$this->loadProxyConfiguration();
|
||||
@@ -135,6 +160,7 @@ class Navbar extends Component
|
||||
// Don't show during normal start/restart flows (starting, restarting, stopping)
|
||||
if (in_array($previousStatus, ['exited', 'stopped', 'unknown', null])) {
|
||||
$this->dispatch('success', 'Proxy is running.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
}
|
||||
break;
|
||||
case 'exited':
|
||||
@@ -142,19 +168,30 @@ class Navbar extends Component
|
||||
// Don't show during normal stop/restart flows (stopping, restarting)
|
||||
if (in_array($previousStatus, ['running'])) {
|
||||
$this->dispatch('info', 'Proxy has exited.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
}
|
||||
break;
|
||||
case 'stopping':
|
||||
$this->dispatch('info', 'Proxy is stopping.');
|
||||
// $this->dispatch('info', 'Proxy is stopping.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
break;
|
||||
case 'starting':
|
||||
$this->dispatch('info', 'Proxy is starting.');
|
||||
// $this->dispatch('info', 'Proxy is starting.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
break;
|
||||
case 'restarting':
|
||||
// $this->dispatch('info', 'Proxy is restarting.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
break;
|
||||
case 'error':
|
||||
$this->dispatch('error', 'Proxy restart failed. Check logs.');
|
||||
$this->lastNotifiedStatus = $this->proxyStatus;
|
||||
break;
|
||||
case 'unknown':
|
||||
$this->dispatch('info', 'Proxy status is unknown.');
|
||||
// Don't notify for unknown status - too noisy
|
||||
break;
|
||||
default:
|
||||
$this->dispatch('info', 'Proxy status updated.');
|
||||
// Don't notify for other statuses
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user