diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index b3432d3ec..d78e49bf9 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -20,11 +20,11 @@ class ContainerStatusJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public function __construct() - { - // + public function __construct( + public string|null $container_id = null, + ) { } - public function handle(): void + protected function checkAllServers() { try { $servers = Server::all()->reject(fn (Server $server) => $server->settings->is_build_server); @@ -57,4 +57,29 @@ class ContainerStatusJob implements ShouldQueue Log::error($e->getMessage()); } } + protected function checkContainerStatus() + { + try { + $application = Application::where('uuid', $this->container_id)->firstOrFail(); + if (!$application) { + return; + } + if ($application->destination->server) { + $container = runRemoteCommandSync($application->destination->server, ["docker inspect --format '{{json .State}}' {$this->container_id}"]); + $container = formatDockerCmdOutputToJson($container); + $application->status = $container[0]['Status']; + $application->save(); + } + } catch (\Exception $e) { + Log::error($e->getMessage()); + } + } + public function handle(): void + { + if ($this->container_id) { + $this->checkContainerStatus(); + } else { + $this->checkAllServers(); + } + } }