From 9854b42f47a676898f9cd11c4f302cff9c104f9f Mon Sep 17 00:00:00 2001 From: "Harry (hjbdev)" Date: Mon, 31 Mar 2025 16:45:36 +0000 Subject: [PATCH] failure handling on steps, setting service status --- app/Enums/DeploymentStatus.php | 1 + app/Jobs/Services/DeployService.php | 3 +++ app/Jobs/Services/RunStep.php | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/app/Enums/DeploymentStatus.php b/app/Enums/DeploymentStatus.php index 50c188b..4b36b0b 100644 --- a/app/Enums/DeploymentStatus.php +++ b/app/Enums/DeploymentStatus.php @@ -7,5 +7,6 @@ enum DeploymentStatus: string case PENDING = 'pending'; case IN_PROGRESS = 'in-progress'; case COMPLETED = 'completed'; + case CANCELLED = 'canceled'; case FAILED = 'failed'; } \ No newline at end of file diff --git a/app/Jobs/Services/DeployService.php b/app/Jobs/Services/DeployService.php index 2679d6a..b9afbff 100644 --- a/app/Jobs/Services/DeployService.php +++ b/app/Jobs/Services/DeployService.php @@ -26,6 +26,9 @@ class DeployService implements ShouldQueue public function handle(): void { $driver = $this->service->driver($this->defaultPassword); + $this->service->update([ + 'status' => ServiceStatus::INSTALLING + ]); $this->deployment = $this->service->deployments()->create([ 'status' => DeploymentStatus::PENDING, ]); diff --git a/app/Jobs/Services/RunStep.php b/app/Jobs/Services/RunStep.php index 7b8e0e6..52827ef 100644 --- a/app/Jobs/Services/RunStep.php +++ b/app/Jobs/Services/RunStep.php @@ -70,4 +70,21 @@ class RunStep implements ShouldQueue ]); } } + + public function failed(\Throwable $exception): void + { + $this->step->update([ + 'status' => DeploymentStatus::FAILED, + 'finished_at' => now(), + 'logs' => $this->step->logs . "\n" . trim($exception->getMessage()), + ]); + + $this->step->deployment->steps()->where('order', '>', $this->step->order)->update([ + 'status' => DeploymentStatus::CANCELLED, + ]); + + $this->step->deployment->update([ + 'status' => DeploymentStatus::FAILED, + ]); + } }