2023-05-15 11:45:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
2023-07-14 11:38:24 +00:00
|
|
|
use App\Actions\Proxy\StartProxy;
|
2023-05-15 11:45:37 +00: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 13:50:36 +00:00
|
|
|
class ProxyCheckJob implements ShouldQueue
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
2023-07-14 11:38:24 +00:00
|
|
|
public function __construct()
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-15 11:45:37 +00:00
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$container_name = 'coolify-proxy';
|
2023-08-24 19:34:24 +00:00
|
|
|
$servers = Server::all();
|
2023-07-14 11:38:24 +00:00
|
|
|
foreach ($servers as $server) {
|
2023-08-24 19:34:24 +00:00
|
|
|
if (
|
|
|
|
$server->settings->is_reachable === false || $server->settings->is_usable === false
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-21 16:00:12 +00:00
|
|
|
$status = getContainerStatus(server: $server, container_id: $container_name);
|
2023-05-15 11:45:37 +00:00
|
|
|
if ($status === 'running') {
|
2023-07-14 11:38:24 +00:00
|
|
|
continue;
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
2023-07-26 13:20:04 +00:00
|
|
|
// $server->team->notify(new ProxyStoppedNotification($server));
|
2023-07-14 11:38:24 +00:00
|
|
|
resolve(StartProxy::class)($server);
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
|
|
|
} catch (\Throwable $th) {
|
2023-07-14 11:01:55 +00:00
|
|
|
ray($th->getMessage());
|
2023-08-24 14:14:09 +00:00
|
|
|
send_internal_notification('ProxyCheckJob failed with: ' . $th->getMessage());
|
2023-08-24 19:09:58 +00:00
|
|
|
throw $th;
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|