diff --git a/app/Invoice/Actions/MassStoreAction.php b/app/Invoice/Actions/MassStoreAction.php index a9995a1a..e42e230f 100644 --- a/app/Invoice/Actions/MassStoreAction.php +++ b/app/Invoice/Actions/MassStoreAction.php @@ -3,6 +3,9 @@ namespace App\Invoice\Actions; use App\Invoice\Models\Invoice; +use App\Lib\JobMiddleware\JobChannels; +use App\Lib\JobMiddleware\WithJobState; +use App\Lib\Queue\TracksJob; use App\Member\Member; use Illuminate\Http\JsonResponse; use Lorisleiva\Actions\ActionRequest; @@ -11,6 +14,7 @@ use Lorisleiva\Actions\Concerns\AsAction; class MassStoreAction { use AsAction; + use TracksJob; /** * @return array @@ -43,8 +47,19 @@ class MassStoreAction public function asController(ActionRequest $request): JsonResponse { - $this->handle($request->year); + $this->startJob($request->year); return response()->json([]); } + + /** + * @param mixed $parameters + */ + public function jobState(WithJobState $jobState, ...$parameters): WithJobState + { + return $jobState + ->after('Zahlungen erstellt') + ->failed('Fehler beim Erstellen von Zahlungen') + ->shouldReload(JobChannels::make()->add('invoice')); + } } diff --git a/app/Lib/Queue/TracksJob.php b/app/Lib/Queue/TracksJob.php index 0b0d2ade..9975b68e 100644 --- a/app/Lib/Queue/TracksJob.php +++ b/app/Lib/Queue/TracksJob.php @@ -17,7 +17,7 @@ trait TracksJob { $jobId = Str::uuid(); $jobState = WithJobState::make($jobId); - $this->jobState(...[$jobState, ...$parameters])->beforeMessage->dispatch(); + tap($this->jobState(...[$jobState, ...$parameters])->beforeMessage, fn ($beforeMessage) => $beforeMessage && $beforeMessage->dispatch());; $parameters[] = $jobId; static::dispatch(...$parameters); }