2023-03-30 15:52:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
2023-05-30 15:52:17 +02:00
|
|
|
use App\Models\ApplicationPreview;
|
2023-03-30 15:52:19 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
2023-05-23 09:53:24 +02:00
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
2023-03-30 15:52:19 +02:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2023-06-02 15:15:12 +02:00
|
|
|
class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
2023-03-30 15:52:19 +02:00
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
2023-05-30 15:52:17 +02:00
|
|
|
public string $container_name;
|
|
|
|
public string|null $pull_request_id;
|
|
|
|
public Application $application;
|
|
|
|
|
|
|
|
public function __construct($application, string $container_name, string|null $pull_request_id = null)
|
|
|
|
{
|
|
|
|
$this->application = $application;
|
|
|
|
$this->container_name = $container_name;
|
|
|
|
$this->pull_request_id = $pull_request_id;
|
2023-03-30 15:52:19 +02:00
|
|
|
}
|
2023-05-23 09:53:24 +02:00
|
|
|
public function uniqueId(): string
|
|
|
|
{
|
2023-05-30 15:52:17 +02:00
|
|
|
return $this->container_name;
|
2023-05-23 09:53:24 +02:00
|
|
|
}
|
2023-04-14 13:18:55 +02:00
|
|
|
public function handle(): void
|
|
|
|
{
|
2023-04-28 10:38:22 +02:00
|
|
|
try {
|
2023-05-30 15:52:17 +02:00
|
|
|
$status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false);
|
|
|
|
if ($this->pull_request_id) {
|
|
|
|
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
|
|
|
|
$preview->status = $status;
|
|
|
|
$preview->save();
|
2023-04-28 10:38:22 +02:00
|
|
|
} else {
|
2023-05-30 15:52:17 +02:00
|
|
|
$this->application->status = $status;
|
|
|
|
$this->application->save();
|
2023-04-28 10:38:22 +02:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
2023-07-26 13:33:48 +02:00
|
|
|
ray($e->getMessage());
|
2023-04-14 13:18:55 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-30 15:52:19 +02:00
|
|
|
}
|