coolify/app/Livewire/Server/Proxy/Status.php

59 lines
1.7 KiB
PHP
Raw Normal View History

2023-06-02 15:15:12 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Server\Proxy;
2023-06-02 15:15:12 +02:00
use App\Actions\Proxy\CheckProxy;
2023-09-18 11:49:26 +02:00
use App\Jobs\ContainerStatusJob;
2023-06-02 15:15:12 +02:00
use App\Models\Server;
use Livewire\Component;
class Status extends Component
{
public Server $server;
public bool $polling = false;
public int $numberOfPolls = 0;
protected $listeners = ['proxyStatusUpdated' => '$refresh', 'startProxyPolling'];
public function startProxyPolling()
{
2023-11-29 14:59:06 +01:00
$this->checkProxy();
}
2023-09-11 22:43:07 +02:00
public function proxyStatusUpdated()
{
2023-09-11 22:29:34 +02:00
$this->server->refresh();
}
public function checkProxy(bool $notification = false)
2023-06-02 15:15:12 +02:00
{
2023-09-11 22:29:34 +02:00
try {
if ($this->polling) {
if ($this->numberOfPolls >= 10) {
$this->polling = false;
$this->numberOfPolls = 0;
2023-12-07 19:06:32 +01:00
$notification && $this->dispatch('error', 'Proxy is not running.');
return;
}
$this->numberOfPolls++;
}
2023-10-17 19:00:23 +02:00
CheckProxy::run($this->server, true);
2023-12-07 19:06:32 +01:00
$this->dispatch('proxyStatusUpdated');
if ($this->server->proxy->status === 'running') {
$this->polling = false;
2023-12-07 19:06:32 +01:00
$notification && $this->dispatch('success', 'Proxy is running.');
} else {
2023-12-07 19:06:32 +01:00
$notification && $this->dispatch('error', 'Proxy is not running.');
}
2023-09-11 22:29:34 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-28 20:29:44 +02:00
}
2023-09-11 22:29:34 +02:00
}
public function getProxyStatus()
2023-09-11 22:43:07 +02:00
{
try {
dispatch_sync(new ContainerStatusJob($this->server));
2023-12-07 19:06:32 +01:00
$this->dispatch('proxyStatusUpdated');
} catch (\Throwable $e) {
return handleError($e, $this);
2023-10-09 11:00:18 +02:00
}
2023-06-02 15:15:12 +02:00
}
}