From d34165714a5515e6fc52639a50b82744ab76d359 Mon Sep 17 00:00:00 2001 From: Maximilian Wedekind Date: Tue, 24 Feb 2026 12:50:43 +0100 Subject: [PATCH 1/5] Insert class and index to ActivityCompleted and ActivityFailed Events as it is in ActivityStarted --- src/Events/ActivityCompleted.php | 2 ++ src/Events/ActivityFailed.php | 2 ++ src/Middleware/ActivityMiddleware.php | 23 ++++++++++++++--------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Events/ActivityCompleted.php b/src/Events/ActivityCompleted.php index 1592fd25..c228c4aa 100644 --- a/src/Events/ActivityCompleted.php +++ b/src/Events/ActivityCompleted.php @@ -15,6 +15,8 @@ class ActivityCompleted public function __construct( public int|string $workflowId, public string $activityId, + public string $class, + public int $index, public string $output, public string $timestamp, ) { diff --git a/src/Events/ActivityFailed.php b/src/Events/ActivityFailed.php index 410b33e5..ddf9a1d7 100644 --- a/src/Events/ActivityFailed.php +++ b/src/Events/ActivityFailed.php @@ -15,6 +15,8 @@ class ActivityFailed public function __construct( public int|string $workflowId, public string $activityId, + public string $class, + public int $index, public string $output, public string $timestamp, ) { diff --git a/src/Middleware/ActivityMiddleware.php b/src/Middleware/ActivityMiddleware.php index 4ee91262..4c54dcc8 100644 --- a/src/Middleware/ActivityMiddleware.php +++ b/src/Middleware/ActivityMiddleware.php @@ -10,7 +10,6 @@ use Workflow\Events\ActivityCompleted; use Workflow\Events\ActivityFailed; use Workflow\Events\ActivityStarted; -use Workflow\Exceptions\TransitionNotFound; final class ActivityMiddleware { @@ -31,8 +30,7 @@ public function handle($job, $next): void $job::class, $job->index, json_encode($job->arguments), - now() - ->format('Y-m-d\TH:i:s.u\Z') + now()->format('Y-m-d\TH:i:s.u\Z') ); try { @@ -43,7 +41,12 @@ public function handle($job, $next): void $file = new SplFileObject($throwable->getFile()); $iterator = new LimitIterator($file, max(0, $throwable->getLine() - 4), 7); - ActivityFailed::dispatch($job->storedWorkflow->id, $this->uuid, json_encode([ + ActivityFailed::dispatch( + $job->storedWorkflow->id, + $this->uuid, + $job::class, + $job->index, + json_encode([ 'class' => get_class($throwable), 'message' => $throwable->getMessage(), 'code' => $throwable->getCode(), @@ -51,8 +54,9 @@ public function handle($job, $next): void 'file' => $throwable->getFile(), 'trace' => $throwable->getTrace(), 'snippet' => array_slice(iterator_to_array($iterator), 0, 7), - ]), now() - ->format('Y-m-d\TH:i:s.u\Z')); + ]), + now()->format('Y-m-d\TH:i:s.u\Z') + ); throw $throwable; } @@ -67,14 +71,15 @@ public function onUnlock(bool $shouldSignal): void ActivityCompleted::dispatch( $this->job->storedWorkflow->id, $this->uuid, + $this->job::class, + $this->job->index, json_encode($this->result), - now() - ->format('Y-m-d\TH:i:s.u\Z') + now()->format('Y-m-d\TH:i:s.u\Z') ); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $throwable) { $this->job->storedWorkflow->toWorkflow() ->fail($throwable); - } catch (TransitionNotFound) { + } catch (\Spatie\ModelStates\Exceptions\TransitionNotFound) { if ($this->job->storedWorkflow->toWorkflow()->running()) { $this->job->release(); } From da056930042ae53d0c748613d09fd0fc544df3c1 Mon Sep 17 00:00:00 2001 From: Maximilian Wedekind Date: Tue, 24 Feb 2026 13:00:11 +0100 Subject: [PATCH 2/5] Fix ECS check --- src/Middleware/ActivityMiddleware.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Middleware/ActivityMiddleware.php b/src/Middleware/ActivityMiddleware.php index 4c54dcc8..6354035b 100644 --- a/src/Middleware/ActivityMiddleware.php +++ b/src/Middleware/ActivityMiddleware.php @@ -30,7 +30,8 @@ public function handle($job, $next): void $job::class, $job->index, json_encode($job->arguments), - now()->format('Y-m-d\TH:i:s.u\Z') + now() + ->format('Y-m-d\TH:i:s.u\Z') ); try { @@ -42,20 +43,21 @@ public function handle($job, $next): void $iterator = new LimitIterator($file, max(0, $throwable->getLine() - 4), 7); ActivityFailed::dispatch( - $job->storedWorkflow->id, + $job->storedWorkflow->id, $this->uuid, $job::class, $job->index, json_encode([ - 'class' => get_class($throwable), - 'message' => $throwable->getMessage(), - 'code' => $throwable->getCode(), - 'line' => $throwable->getLine(), - 'file' => $throwable->getFile(), - 'trace' => $throwable->getTrace(), - 'snippet' => array_slice(iterator_to_array($iterator), 0, 7), + 'class' => get_class($throwable), + 'message' => $throwable->getMessage(), + 'code' => $throwable->getCode(), + 'line' => $throwable->getLine(), + 'file' => $throwable->getFile(), + 'trace' => $throwable->getTrace(), + 'snippet' => array_slice(iterator_to_array($iterator), 0, 7), ]), - now()->format('Y-m-d\TH:i:s.u\Z') + now() + ->format('Y-m-d\TH:i:s.u\Z') ); throw $throwable; @@ -74,7 +76,8 @@ public function onUnlock(bool $shouldSignal): void $this->job::class, $this->job->index, json_encode($this->result), - now()->format('Y-m-d\TH:i:s.u\Z') + now() + ->format('Y-m-d\TH:i:s.u\Z') ); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $throwable) { $this->job->storedWorkflow->toWorkflow() From d47f0fce5caebd00415cbb9641b6c2d2d5321ebf Mon Sep 17 00:00:00 2001 From: Maximilian Wedekind Date: Tue, 24 Feb 2026 13:03:40 +0100 Subject: [PATCH 3/5] ECS check should be succeed now.. --- src/Middleware/ActivityMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/ActivityMiddleware.php b/src/Middleware/ActivityMiddleware.php index 6354035b..b4aae6b6 100644 --- a/src/Middleware/ActivityMiddleware.php +++ b/src/Middleware/ActivityMiddleware.php @@ -55,7 +55,7 @@ public function handle($job, $next): void 'file' => $throwable->getFile(), 'trace' => $throwable->getTrace(), 'snippet' => array_slice(iterator_to_array($iterator), 0, 7), - ]), + ]), now() ->format('Y-m-d\TH:i:s.u\Z') ); From 9e8775b3f50f34cd7f64d67581fcf7621ad4c4db Mon Sep 17 00:00:00 2001 From: Maximilian Wedekind Date: Tue, 24 Feb 2026 13:16:02 +0100 Subject: [PATCH 4/5] add package "spatie/laravel-model-states" to required packages as it is used in ActivityMiddleware --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7ec379e2..f44205ad 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ "require": { "php": "^8.1", "laravel/framework": "^9.0|^10.0|^11.0|^12.0", - "react/promise": "^2.9|^3.0" + "react/promise": "^2.9|^3.0", + "spatie/laravel-model-states": "^2.0" }, "require-dev": { "orchestra/testbench": "^8.0", From ea53fa515ec3cd0e621d689d544b368e573a53f1 Mon Sep 17 00:00:00 2001 From: Maximilian Wedekind Date: Tue, 24 Feb 2026 14:05:02 +0100 Subject: [PATCH 5/5] change events to improve backwards compability. Also remove spatie/TransitionNotFound as it was an error. --- composer.json | 3 +-- src/Events/ActivityCompleted.php | 4 ++-- src/Events/ActivityFailed.php | 4 ++-- src/Middleware/ActivityMiddleware.php | 15 ++++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index f44205ad..7ec379e2 100644 --- a/composer.json +++ b/composer.json @@ -51,8 +51,7 @@ "require": { "php": "^8.1", "laravel/framework": "^9.0|^10.0|^11.0|^12.0", - "react/promise": "^2.9|^3.0", - "spatie/laravel-model-states": "^2.0" + "react/promise": "^2.9|^3.0" }, "require-dev": { "orchestra/testbench": "^8.0", diff --git a/src/Events/ActivityCompleted.php b/src/Events/ActivityCompleted.php index c228c4aa..eb8e1003 100644 --- a/src/Events/ActivityCompleted.php +++ b/src/Events/ActivityCompleted.php @@ -15,10 +15,10 @@ class ActivityCompleted public function __construct( public int|string $workflowId, public string $activityId, - public string $class, - public int $index, public string $output, public string $timestamp, + public string $class, + public int $index ) { } } diff --git a/src/Events/ActivityFailed.php b/src/Events/ActivityFailed.php index ddf9a1d7..c17f5460 100644 --- a/src/Events/ActivityFailed.php +++ b/src/Events/ActivityFailed.php @@ -15,10 +15,10 @@ class ActivityFailed public function __construct( public int|string $workflowId, public string $activityId, - public string $class, - public int $index, public string $output, public string $timestamp, + public string $class, + public int $index ) { } } diff --git a/src/Middleware/ActivityMiddleware.php b/src/Middleware/ActivityMiddleware.php index b4aae6b6..6c1f2205 100644 --- a/src/Middleware/ActivityMiddleware.php +++ b/src/Middleware/ActivityMiddleware.php @@ -10,6 +10,7 @@ use Workflow\Events\ActivityCompleted; use Workflow\Events\ActivityFailed; use Workflow\Events\ActivityStarted; +use Workflow\Exceptions\TransitionNotFound; final class ActivityMiddleware { @@ -45,8 +46,6 @@ public function handle($job, $next): void ActivityFailed::dispatch( $job->storedWorkflow->id, $this->uuid, - $job::class, - $job->index, json_encode([ 'class' => get_class($throwable), 'message' => $throwable->getMessage(), @@ -57,7 +56,9 @@ public function handle($job, $next): void 'snippet' => array_slice(iterator_to_array($iterator), 0, 7), ]), now() - ->format('Y-m-d\TH:i:s.u\Z') + ->format('Y-m-d\TH:i:s.u\Z'), + $job::class, + $job->index ); throw $throwable; @@ -73,16 +74,16 @@ public function onUnlock(bool $shouldSignal): void ActivityCompleted::dispatch( $this->job->storedWorkflow->id, $this->uuid, - $this->job::class, - $this->job->index, json_encode($this->result), now() - ->format('Y-m-d\TH:i:s.u\Z') + ->format('Y-m-d\TH:i:s.u\Z'), + $this->job::class, + $this->job->index ); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $throwable) { $this->job->storedWorkflow->toWorkflow() ->fail($throwable); - } catch (\Spatie\ModelStates\Exceptions\TransitionNotFound) { + } catch (TransitionNotFound) { if ($this->job->storedWorkflow->toWorkflow()->running()) { $this->job->release(); }