2024-05-08 17:19:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Actions\Server\StartSentinel;
|
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
class PullSentinelImageJob implements ShouldBeEncrypted, ShouldQueue
|
2024-05-08 17:19:32 +00:00
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
public $timeout = 1000;
|
|
|
|
|
|
|
|
public function middleware(): array
|
|
|
|
{
|
|
|
|
return [(new WithoutOverlapping($this->server->uuid))];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uniqueId(): string
|
|
|
|
{
|
|
|
|
return $this->server->uuid;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-06-22 08:41:55 +00:00
|
|
|
public function __construct(public Server $server) {}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-08 17:19:32 +00:00
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$version = get_latest_sentinel_version();
|
2024-06-18 14:43:18 +00:00
|
|
|
if (! $version) {
|
2024-05-08 17:19:32 +00:00
|
|
|
ray('Failed to get latest Sentinel version');
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-08 17:19:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-05-09 10:10:06 +00:00
|
|
|
$local_version = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/version"'], $this->server, false);
|
|
|
|
if (empty($local_version)) {
|
|
|
|
$local_version = '0.0.0';
|
|
|
|
}
|
2024-05-08 17:32:13 +00:00
|
|
|
if (version_compare($local_version, $version, '<')) {
|
|
|
|
StartSentinel::run($this->server, $version, true);
|
2024-06-18 14:43:18 +00:00
|
|
|
|
2024-05-08 17:19:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-05-08 17:32:13 +00:00
|
|
|
ray('Sentinel image is up to date');
|
2024-05-08 17:19:32 +00:00
|
|
|
} catch (\Throwable $e) {
|
2024-06-20 11:17:06 +00:00
|
|
|
// send_internal_notification('PullSentinelImageJob failed with: '.$e->getMessage());
|
2024-05-08 17:19:32 +00:00
|
|
|
ray($e->getMessage());
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|