Skip to content

Commit 6dbb8fe

Browse files
committed
added retry method
1 parent cee8929 commit 6dbb8fe

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Models/Process.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Yuges\Package\Models\Model;
66
use Yuges\Processable\Config\Config;
7+
use Yuges\Processable\Enums\StageState;
78
use Yuges\Processable\Traits\HasStages;
9+
use Illuminate\Support\Facades\Artisan;
810
use Yuges\Processable\Traits\HasProcessable;
911
use Yuges\Processable\Traits\HasProcessState;
1012
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -29,4 +31,20 @@ public function getTable(): string
2931
{
3032
return Config::getProcessTable() ?? $this->table;
3133
}
34+
35+
public function retry(): self
36+
{
37+
/** @var ?Stage */
38+
$stage = $this->stages()->getQuery()
39+
->where('state', '=', Config::getStageStateClass(StageState::class)::Failed)
40+
->first();
41+
42+
if (! $stage?->job_uuid) {
43+
return $this;
44+
}
45+
46+
Artisan::call("queue:retry {$stage->job_uuid}");
47+
48+
return $this;
49+
}
3250
}

tests/Integration/ProcessTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ public function testProcessPost()
2222
]);
2323

2424
$process = $post->process(TestProcess::class);
25+
26+
$process->retry();
2527
}
2628
}

0 commit comments

Comments
 (0)