Skip to content

Commit 6a275fe

Browse files
author
A. Van Driessche
authored
Merge pull request #2354 from codeeu/504-error-certificates
Queue the generation of certificates
2 parents 9d0d60e + 48d0306 commit 6a275fe

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

app/Http/Controllers/ParticipationController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public function generate(Request $request): RedirectResponse
5252
$participation->save();
5353

5454
//Dispatch Job
55-
GenerateCertificatesOfParticipation::dispatchSync($participation);
55+
GenerateCertificatesOfParticipation::dispatch($participation);
5656

5757
return redirect()->route('certificates');
58-
5958
}
6059
}

app/Jobs/GenerateCertificatesOfParticipation.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ class GenerateCertificatesOfParticipation implements ShouldQueue
1616

1717
protected Participation $participation;
1818

19+
/**
20+
* The number of times the job may be attempted.
21+
*
22+
* @var int
23+
*/
24+
public $tries = 3;
25+
26+
/**
27+
* The number of seconds the job can run before timing out.
28+
*
29+
* @var int
30+
*/
31+
public $timeout = 300;
32+
1933
/**
2034
* Create a new job instance.
2135
*
@@ -34,14 +48,21 @@ public function handle(): void
3448
$names = array_map('trim', explode(',', $this->participation->names));
3549

3650
$this->participation['status'] = 'PROCESSING';
37-
3851
$this->participation->save();
3952

4053
$zipUrl = CertificatesHelper::doGenerateCertificatesOfParticipation($names, $this->participation->event_name, $this->participation->event_date);
4154

4255
$this->participation['participation_url'] = $zipUrl;
4356
$this->participation['status'] = 'DONE';
57+
$this->participation->save();
58+
}
4459

60+
/**
61+
* Handle a job failure.
62+
*/
63+
public function failed(\Throwable $exception): void
64+
{
65+
$this->participation['status'] = 'FAILED';
4566
$this->participation->save();
4667
}
4768
}

0 commit comments

Comments
 (0)