update scheduled jobs

This commit is contained in:
Andras Bacsai
2023-04-28 10:38:22 +02:00
parent bc6feed17f
commit b733865cb5
2 changed files with 48 additions and 48 deletions

View File

@@ -21,15 +21,18 @@ class ContainerStatusJob implements ShouldQueue
} }
public function handle(): void public function handle(): void
{ {
try {
if ($this->container_id) { if ($this->container_id) {
$this->checkContainerStatus(); $this->checkContainerStatus();
} else { } else {
$this->checkAllServers(); $this->checkAllServers();
} }
} catch (\Exception $e) {
Log::error($e->getMessage());
}
} }
protected function checkAllServers() protected function checkAllServers()
{ {
try {
$servers = Server::all()->reject(fn (Server $server) => $server->settings->is_build_server); $servers = Server::all()->reject(fn (Server $server) => $server->settings->is_build_server);
$applications = Application::all(); $applications = Application::all();
$not_found_applications = $applications; $not_found_applications = $applications;
@@ -56,13 +59,9 @@ class ContainerStatusJob implements ShouldQueue
$not_found_application->save(); $not_found_application->save();
Log::info('Not found application: ' . $not_found_application->uuid . '. Set status to: ' . $not_found_application->status); Log::info('Not found application: ' . $not_found_application->uuid . '. Set status to: ' . $not_found_application->status);
} }
} catch (\Exception $e) {
Log::error($e->getMessage());
}
} }
protected function checkContainerStatus() protected function checkContainerStatus()
{ {
try {
$application = Application::where('uuid', $this->container_id)->firstOrFail(); $application = Application::where('uuid', $this->container_id)->firstOrFail();
if (!$application) { if (!$application) {
return; return;
@@ -73,8 +72,5 @@ class ContainerStatusJob implements ShouldQueue
$application->status = $container[0]['Status']; $application->status = $container[0]['Status'];
$application->save(); $application->save();
} }
} catch (\Exception $e) {
Log::error($e->getMessage());
}
} }
} }

View File

@@ -28,9 +28,13 @@ class DockerCleanupDanglingImagesJob implements ShouldQueue
*/ */
public function handle(): void public function handle(): void
{ {
try {
$servers = Server::all(); $servers = Server::all();
foreach ($servers as $server) { foreach ($servers as $server) {
runRemoteCommandSync($server, ['docker image prune -f']); runRemoteCommandSync($server, ['docker image prune -f']);
} }
} catch (\Exception $e) {
Log::error($e->getMessage());
}
} }
} }