coolify/app/Jobs/ProxyCheckJob.php

49 lines
1.5 KiB
PHP
Raw Normal View History

2023-05-15 13:45:37 +02:00
<?php
namespace App\Jobs;
use App\Actions\Proxy\InstallProxy;
2023-05-26 09:45:18 +02:00
use App\Enums\ProxyTypes;
2023-05-15 13:45:37 +02:00
use App\Models\Server;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2023-07-07 15:50:36 +02:00
class ProxyCheckJob implements ShouldQueue
2023-05-15 13:45:37 +02:00
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected Server|null $server)
2023-05-15 13:45:37 +02:00
{
}
public function handle()
{
try {
$container_name = 'coolify-proxy';
if ($this->server) {
ray('Checking proxy for server: ' . $this->server->name);
$status = get_container_status(server: $this->server, container_id: $container_name);
2023-05-15 13:45:37 +02:00
if ($status === 'running') {
return;
}
resolve(InstallProxy::class)($this->server);
} else {
$servers = Server::whereRelation('settings', 'is_usable', true)->get();
foreach ($servers as $server) {
$status = get_container_status(server: $server, container_id: $container_name);
if ($status === 'running') {
continue;
}
resolve(InstallProxy::class)($server);
2023-05-15 13:45:37 +02:00
}
}
} catch (\Throwable $th) {
ray($th->getMessage());
2023-05-15 13:45:37 +02:00
//throw $th;
}
}
}