diff --git a/app/Http/Controllers/ParticipationController.php b/app/Http/Controllers/ParticipationController.php index 3ba3fd89e..3735729d4 100644 --- a/app/Http/Controllers/ParticipationController.php +++ b/app/Http/Controllers/ParticipationController.php @@ -52,9 +52,8 @@ public function generate(Request $request): RedirectResponse $participation->save(); //Dispatch Job - GenerateCertificatesOfParticipation::dispatchSync($participation); + GenerateCertificatesOfParticipation::dispatch($participation); return redirect()->route('certificates'); - } } diff --git a/app/Jobs/GenerateCertificatesOfParticipation.php b/app/Jobs/GenerateCertificatesOfParticipation.php index 4e162e386..7285bf84b 100644 --- a/app/Jobs/GenerateCertificatesOfParticipation.php +++ b/app/Jobs/GenerateCertificatesOfParticipation.php @@ -16,6 +16,20 @@ class GenerateCertificatesOfParticipation implements ShouldQueue protected Participation $participation; + /** + * The number of times the job may be attempted. + * + * @var int + */ + public $tries = 3; + + /** + * The number of seconds the job can run before timing out. + * + * @var int + */ + public $timeout = 300; + /** * Create a new job instance. * @@ -34,14 +48,21 @@ public function handle(): void $names = array_map('trim', explode(',', $this->participation->names)); $this->participation['status'] = 'PROCESSING'; - $this->participation->save(); $zipUrl = CertificatesHelper::doGenerateCertificatesOfParticipation($names, $this->participation->event_name, $this->participation->event_date); $this->participation['participation_url'] = $zipUrl; $this->participation['status'] = 'DONE'; + $this->participation->save(); + } + /** + * Handle a job failure. + */ + public function failed(\Throwable $exception): void + { + $this->participation['status'] = 'FAILED'; $this->participation->save(); } }