coolify/app/Jobs/ProxyStartJob.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2023-07-14 13:38:24 +02:00
<?php
namespace App\Jobs;
use App\Actions\Proxy\StartProxy;
2023-09-01 10:02:24 +02:00
use App\Enums\ProxyStatus;
use App\Enums\ProxyTypes;
2023-07-14 13:38:24 +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;
class ProxyStartJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected Server $server)
{
}
2023-07-14 13:38:24 +02:00
public function handle()
{
try {
$container_name = 'coolify-proxy';
ray('Starting proxy for server: ' . $this->server->name);
2023-08-21 18:00:12 +02:00
$status = getContainerStatus(server: $this->server, container_id: $container_name);
2023-07-14 13:38:24 +02:00
if ($status === 'running') {
return;
}
2023-09-01 10:02:24 +02:00
if (is_null(data_get($this->server, 'proxy.type'))) {
$this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value;
$this->server->proxy->status = ProxyStatus::EXITED->value;
$this->server->save();
}
2023-07-14 13:38:24 +02:00
resolve(StartProxy::class)($this->server);
} catch (\Throwable $th) {
2023-08-24 16:14:09 +02:00
send_internal_notification('ProxyStartJob failed with: ' . $th->getMessage());
2023-07-14 13:38:24 +02:00
ray($th->getMessage());
2023-08-24 21:09:58 +02:00
throw $th;
2023-07-14 13:38:24 +02:00
}
}
}