lasthourcloud/app/Http/Livewire/Server/Proxy/Status.php

59 lines
1.7 KiB
PHP
Raw Normal View History

2023-06-02 13:15:12 +00:00
<?php
namespace App\Http\Livewire\Server\Proxy;
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;
public bool $polling = false;
public int $numberOfPolls = 0;
protected $listeners = ['proxyStatusUpdated', 'startProxyPolling'];
public function startProxyPolling()
{
$this->polling = true;
}
2023-09-11 20:43:07 +00:00
public function proxyStatusUpdated()
{
2023-09-11 20:29:34 +00:00
$this->server->refresh();
}
public function checkProxy(bool $notification = false)
2023-06-02 13:15:12 +00:00
{
2023-09-11 20:29:34 +00:00
try {
if ($this->polling) {
if ($this->numberOfPolls >= 10) {
$this->polling = false;
$this->numberOfPolls = 0;
$notification && $this->emit('error', 'Proxy is not running.');
return;
}
$this->numberOfPolls++;
}
2023-10-17 17:00:23 +00:00
CheckProxy::run($this->server, true);
2023-09-28 09:33:16 +00:00
$this->emit('proxyStatusUpdated');
if ($this->server->proxy->status === 'running') {
$this->polling = false;
$notification && $this->emit('success', 'Proxy is running.');
} else {
$notification && $this->emit('error', 'Proxy is not running.');
}
2023-09-11 20:29:34 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-28 18:29:44 +00:00
}
2023-09-11 20:29:34 +00:00
}
public function getProxyStatus()
2023-09-11 20:43:07 +00:00
{
try {
dispatch_sync(new ContainerStatusJob($this->server));
$this->emit('proxyStatusUpdated');
} catch (\Throwable $e) {
return handleError($e, $this);
2023-10-09 09:00:18 +00:00
}
2023-06-02 13:15:12 +00:00
}
}