Skip to content

Commit d94bf70

Browse files
authored
Normalize Activity Events (#337)
1 parent 4148e90 commit d94bf70

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/Events/ActivityCompleted.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function __construct(
1717
public string $activityId,
1818
public string $output,
1919
public string $timestamp,
20+
public string $class,
21+
public int $index
2022
) {
2123
}
2224
}

src/Events/ActivityFailed.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function __construct(
1717
public string $activityId,
1818
public string $output,
1919
public string $timestamp,
20+
public string $class,
21+
public int $index
2022
) {
2123
}
2224
}

src/Middleware/ActivityMiddleware.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,23 @@ public function handle($job, $next): void
4343
$file = new SplFileObject($throwable->getFile());
4444
$iterator = new LimitIterator($file, max(0, $throwable->getLine() - 4), 7);
4545

46-
ActivityFailed::dispatch($job->storedWorkflow->id, $this->uuid, json_encode([
47-
'class' => get_class($throwable),
48-
'message' => $throwable->getMessage(),
49-
'code' => $throwable->getCode(),
50-
'line' => $throwable->getLine(),
51-
'file' => $throwable->getFile(),
52-
'trace' => $throwable->getTrace(),
53-
'snippet' => array_slice(iterator_to_array($iterator), 0, 7),
54-
]), now()
55-
->format('Y-m-d\TH:i:s.u\Z'));
46+
ActivityFailed::dispatch(
47+
$job->storedWorkflow->id,
48+
$this->uuid,
49+
json_encode([
50+
'class' => get_class($throwable),
51+
'message' => $throwable->getMessage(),
52+
'code' => $throwable->getCode(),
53+
'line' => $throwable->getLine(),
54+
'file' => $throwable->getFile(),
55+
'trace' => $throwable->getTrace(),
56+
'snippet' => array_slice(iterator_to_array($iterator), 0, 7),
57+
]),
58+
now()
59+
->format('Y-m-d\TH:i:s.u\Z'),
60+
$job::class,
61+
$job->index
62+
);
5663

5764
throw $throwable;
5865
}
@@ -69,7 +76,9 @@ public function onUnlock(bool $shouldSignal): void
6976
$this->uuid,
7077
json_encode($this->result),
7178
now()
72-
->format('Y-m-d\TH:i:s.u\Z')
79+
->format('Y-m-d\TH:i:s.u\Z'),
80+
$this->job::class,
81+
$this->job->index
7382
);
7483
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $throwable) {
7584
$this->job->storedWorkflow->toWorkflow()

0 commit comments

Comments
 (0)