Fix duplicate proxy restart notifications

- Remove redundant ProxyStatusChangedUI dispatch from RestartProxyJob
  (ProxyStatusChanged event already triggers the listener that dispatches it)
- Remove redundant Traefik version check from RestartProxyJob
  (already handled by ProxyStatusChangedNotification listener)
- Add lastNotifiedStatus tracking to prevent duplicate toasts
- Remove notifications for unknown/default statuses (too noisy)
- Simplify RestartProxyJob to only handle stop/start logic

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andras BacsaiandClaude committed 2025-12-03 16:09:47 +01:00
1 parent e4810a28d2
commit b00d8902f4
3 files changed
+68 -84

No files matched your search

+4 -20
View File
@@ -4,7 +4,6 @@ namespace App\Jobs;
use App\Actions\Proxy\StartProxy;
use App\Actions\Proxy\StopProxy;
use App\Enums\ProxyTypes;
use App\Events\ProxyStatusChangedUI;
use App\Models\Server;
use Illuminate\Bus\Queueable;
@@ -14,7 +13,6 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class RestartProxyJob implements ShouldBeEncrypted, ShouldQueue
{
@@ -36,8 +34,6 @@ class RestartProxyJob implements ShouldBeEncrypted, ShouldQueue
public function handle()
{
try {
$teamId = $this->server->team_id;
// Stop proxy
StopProxy::run($this->server, restarting: true);
@@ -45,26 +41,14 @@ class RestartProxyJob implements ShouldBeEncrypted, ShouldQueue
$this->server->proxy->force_stop = false;
$this->server->save();
// Start proxy asynchronously to get activity
// Start proxy asynchronously - the ProxyStatusChanged event will be dispatched
// when the remote process completes, which triggers ProxyStatusChangedNotification
// listener that handles UI updates and Traefik version checks
$activity = StartProxy::run($this->server, force: true, restarting: true);
// Store activity ID and dispatch event with it
// Store activity ID for reference
if ($activity && is_object($activity)) {
$this->activity_id = $activity->id;
ProxyStatusChangedUI::dispatch($teamId, $this->activity_id);
}
// Check Traefik version after restart (same as original behavior)
if ($this->server->proxyType() === ProxyTypes::TRAEFIK->value) {
$traefikVersions = get_traefik_versions();
if ($traefikVersions !== null) {
CheckTraefikVersionForServerJob::dispatch($this->server, $traefikVersions);
} else {
Log::warning('Traefik version check skipped: versions.json data unavailable', [
'server_id' => $this->server->id,
'server_name' => $this->server->name,
]);
}
}
} catch (\Throwable $e) {
+15 -3
View File
@@ -6,7 +6,6 @@ use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Actions\Proxy\StopProxy;
use App\Enums\ProxyTypes;
use App\Jobs\CheckTraefikVersionForServerJob;
use App\Jobs\RestartProxyJob;
use App\Models\Server;
use App\Services\ProxyDashboardCacheService;
@@ -29,6 +28,8 @@ class Navbar extends Component
public ?string $proxyStatus = 'unknown';
public ?string $lastNotifiedStatus = null;
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
@@ -133,6 +134,11 @@ class Navbar extends Component
$this->dispatch('activityMonitor', $event['activityId']);
}
// Skip notification if we already notified about this status (prevents duplicates)
if ($this->lastNotifiedStatus === $this->proxyStatus) {
return;
}
switch ($this->proxyStatus) {
case 'running':
$this->loadProxyConfiguration();
@@ -140,6 +146,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':
@@ -147,25 +154,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->lastNotifiedStatus = $this->proxyStatus;
break;
case '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;
}