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