From a9870ad1971d92535eee9e93de4d65951f0dd292 Mon Sep 17 00:00:00 2001 From: Quentin Gabriele Date: Sat, 21 Sep 2024 15:39:22 +0200 Subject: [PATCH] add shouldCancel and shouldRun --- src/Models/Workflow.php | 9 ++++++++- src/WorkflowDefinition.php | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Models/Workflow.php b/src/Models/Workflow.php index a68e182..921baf2 100644 --- a/src/Models/Workflow.php +++ b/src/Models/Workflow.php @@ -257,11 +257,18 @@ public function run( if ( $this->isFinished() || $this->isFailed() || - $this->isCanceled() + $this->isCanceled() || + ! $this->definition->shouldRun() ) { return; } + if ($this->definition->shouldCancel()) { + $this->markAsCanceled(); + + return; + } + $readySteps = $this->definition ->steps($this) ->filter(function ($step, $name) { diff --git a/src/WorkflowDefinition.php b/src/WorkflowDefinition.php index 9235262..42ccf4d 100644 --- a/src/WorkflowDefinition.php +++ b/src/WorkflowDefinition.php @@ -27,4 +27,14 @@ public function start(): Workflow return $workflow; } + + public function shouldCancel(): bool + { + return false; + } + + public function shouldRun(): bool + { + return true; + } }