Skip to content

Commit a1b365d

Browse files
committed
exception to error
1 parent 3c5f993 commit a1b365d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/Actions/UpdateProcessStageAction.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Yuges\Processable\Actions;
44

5+
use Throwable;
56
use Carbon\Carbon;
67
use Yuges\Processable\Models\Stage;
78
use Illuminate\Contracts\Queue\Job;
89
use Yuges\Processable\Enums\StageState;
10+
use Yuges\Processable\Error\StageError;
911
use Yuges\Processable\Interfaces\StageState as StageStateInterface;
1012

1113
class UpdateProcessStageAction
@@ -20,14 +22,23 @@ public static function create(Stage $stage): self
2022
return new static($stage);
2123
}
2224

23-
public function execute(StageStateInterface $state, ?Job $job = null): Stage
25+
public function execute(StageStateInterface $state, ?Job $job = null, ?Throwable $e = null): Stage
2426
{
2527
$attributes = [
2628
'state' => $state,
2729
'job_id' => $job?->getJobId() ?? $this->stage->job_id,
2830
'job_uuid' => $job?->uuid() ?? $this->stage->job_uuid,
2931
];
3032

33+
if ($e) {
34+
$attributes['error'] = new StageError(
35+
$e->getMessage(),
36+
$e->getCode(),
37+
$e->getFile(),
38+
$e->getLine(),
39+
);
40+
}
41+
3142
match ($state->value) {
3243
StageState::Started->value => $attributes['started_at'] = Carbon::now(),
3344
StageState::Finished->value => $attributes['finished_at'] = Carbon::now(),

src/Handlers/StageEventHandler.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public static function create(): self
1818

1919
public function before(JobProcessing $event): void
2020
{
21-
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class))
22-
{
21+
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class)) {
2322
return;
2423
}
2524

@@ -35,8 +34,7 @@ public function before(JobProcessing $event): void
3534

3635
public function after(JobProcessed $event): void
3736
{
38-
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class))
39-
{
37+
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class)) {
4038
return;
4139
}
4240

@@ -52,8 +50,7 @@ public function after(JobProcessed $event): void
5250

5351
public function failing(JobFailed $event): void
5452
{
55-
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class))
56-
{
53+
if ($event->job->resolveName() != Config::getProcessStageJobClass(ProcessStageJob::class)) {
5754
return;
5855
}
5956

@@ -64,6 +61,10 @@ public function failing(JobFailed $event): void
6461
return;
6562
}
6663

67-
Config::getUpdateProcessStageAction($job->getStage())->execute(StageState::Failed, $event->job);
64+
Config::getUpdateProcessStageAction($job->getStage())->execute(
65+
StageState::Failed,
66+
$event->job,
67+
$event->exception
68+
);
6869
}
6970
}

0 commit comments

Comments
 (0)