|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Imtigger\LaravelJobStatus\EventManagers; |
| 4 | + |
| 5 | +use Carbon\Carbon; |
| 6 | +use Illuminate\Queue\Events\JobExceptionOccurred; |
| 7 | +use Illuminate\Queue\Events\JobFailed; |
| 8 | +use Illuminate\Queue\Events\JobProcessed; |
| 9 | +use Illuminate\Queue\Events\JobProcessing; |
| 10 | + |
| 11 | +class DefaultEventManager extends EventManager |
| 12 | +{ |
| 13 | + public function before(JobProcessing $event): void |
| 14 | + { |
| 15 | + $this->getUpdater()->update($event, [ |
| 16 | + 'status' => $this->getEntity()::STATUS_EXECUTING, |
| 17 | + 'job_id' => $event->job->getJobId(), |
| 18 | + 'queue' => $event->job->getQueue(), |
| 19 | + 'started_at' => Carbon::now(), |
| 20 | + ]); |
| 21 | + } |
| 22 | + |
| 23 | + public function after(JobProcessed $event): void |
| 24 | + { |
| 25 | + $this->getUpdater()->update($event, [ |
| 26 | + 'status' => $this->getEntity()::STATUS_FINISHED, |
| 27 | + 'finished_at' => Carbon::now(), |
| 28 | + ]); |
| 29 | + } |
| 30 | + |
| 31 | + public function failing(JobFailed $event): void |
| 32 | + { |
| 33 | + $this->getUpdater()->update($event, [ |
| 34 | + 'status' => $this->getEntity()::STATUS_FAILED, |
| 35 | + 'finished_at' => Carbon::now(), |
| 36 | + ]); |
| 37 | + } |
| 38 | + |
| 39 | + public function exceptionOccurred(JobExceptionOccurred $event): void |
| 40 | + { |
| 41 | + $this->getUpdater()->update($event, [ |
| 42 | + 'status' => $this->getEntity()::STATUS_RETRYING, |
| 43 | + 'finished_at' => Carbon::now(), |
| 44 | + 'output' => ['message' => $event->exception->getMessage()], |
| 45 | + ]); |
| 46 | + } |
| 47 | +} |
0 commit comments