Skip to content

Commit 71a8694

Browse files
authored
Added workflowId to ActivityCompleted and ActivityFailed (laravel-workflow#160)
* Added workflowId to ActivityFailed event * Added workflowId to ActivityCompleted event
1 parent 6e8c497 commit 71a8694

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

src/Events/ActivityCompleted.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ActivityCompleted
1313
use InteractsWithSockets;
1414

1515
public function __construct(
16+
public int|string $workflowId,
1617
public string $activityId,
1718
public string $output,
1819
public string $timestamp,

src/Events/ActivityFailed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ActivityFailed
1313
use InteractsWithSockets;
1414

1515
public function __construct(
16+
public int|string $workflowId,
1617
public string $activityId,
1718
public string $output,
1819
public string $timestamp,

src/Middleware/WorkflowMiddleware.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public function handle($job, $next): void
4444
try {
4545
$job->storedWorkflow->toWorkflow()
4646
->next($job->index, $job->now, $job::class, $result);
47-
ActivityCompleted::dispatch($uuid, json_encode($result), now()->format('Y-m-d\TH:i:s.u\Z'));
47+
ActivityCompleted::dispatch(
48+
$job->storedWorkflow->id,
49+
$uuid,
50+
json_encode($result),
51+
now()
52+
->format('Y-m-d\TH:i:s.u\Z')
53+
);
4854
} catch (\Spatie\ModelStates\Exceptions\TransitionNotFound) {
4955
if ($job->storedWorkflow->toWorkflow()->running()) {
5056
$job->release();
@@ -54,7 +60,7 @@ public function handle($job, $next): void
5460
$file = new SplFileObject($throwable->getFile());
5561
$iterator = new LimitIterator($file, max(0, $throwable->getLine() - 4), 7);
5662

57-
ActivityFailed::dispatch($uuid, json_encode([
63+
ActivityFailed::dispatch($job->storedWorkflow->id, $uuid, json_encode([
5864
'class' => get_class($throwable),
5965
'message' => $throwable->getMessage(),
6066
'code' => $throwable->getCode(),

tests/Unit/Listeners/MonitorActivityCompletedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testHandle(): void
3333
"rest/v1/activities?id=eq.{$activityId}" => Http::response(),
3434
]);
3535

36-
$event = new ActivityCompleted($activityId, 'output', 'time');
36+
$event = new ActivityCompleted(1, $activityId, 'output', 'time');
3737
$listener = new MonitorActivityCompleted();
3838
$listener->handle($event);
3939

tests/Unit/Listeners/MonitorActivityFailedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testHandle(): void
3333
"rest/v1/activities?id=eq.{$activityId}" => Http::response(),
3434
]);
3535

36-
$event = new ActivityFailed($activityId, 'output', 'time');
36+
$event = new ActivityFailed(1, $activityId, 'output', 'time');
3737
$listener = new MonitorActivityFailed();
3838
$listener->handle($event);
3939

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy