|
2 | 2 |
|
3 | 3 | namespace CSlant\GitHubProject\Jobs; |
4 | 4 |
|
| 5 | +use CSlant\GitHubProject\Constants\WebHookConstant; |
| 6 | +use Illuminate\Bus\Queueable; |
5 | 7 | use Illuminate\Contracts\Queue\ShouldQueue; |
6 | | -use Illuminate\Foundation\Queue\Queueable; |
| 8 | +use Illuminate\Foundation\Bus\Dispatchable; |
| 9 | +use Illuminate\Queue\InteractsWithQueue; |
| 10 | +use Illuminate\Queue\SerializesModels; |
| 11 | +use Illuminate\Support\Facades\Cache; |
7 | 12 |
|
8 | 13 | class ProcessWebhookEvent implements ShouldQueue |
9 | 14 | { |
10 | | - use Queueable; |
| 15 | + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| 16 | + |
| 17 | + protected array $eventData; |
11 | 18 |
|
12 | 19 | /** |
13 | 20 | * Create a new job instance. |
| 21 | + * |
| 22 | + * @param array $eventData |
14 | 23 | */ |
15 | | - public function __construct() |
| 24 | + public function __construct(array $eventData) |
16 | 25 | { |
17 | | - // |
| 26 | + $this->eventData = $eventData; |
18 | 27 | } |
19 | 28 |
|
20 | 29 | /** |
21 | 30 | * Execute the job. |
22 | 31 | */ |
23 | | - public function handle(): void |
| 32 | + public function handle() |
24 | 33 | { |
25 | | - // |
| 34 | + $events = Cache::get(WebHookConstant::WEBHOOK_CACHE_NAME, []); |
| 35 | + $events[] = $this->eventData; |
| 36 | + Cache::put(WebHookConstant::WEBHOOK_CACHE_NAME, $events, now()->addSeconds(20)); |
| 37 | + |
| 38 | + if (count($events) === 1) { |
| 39 | + ProcessAggregatedEvents::dispatch()->delay(now()->addSeconds(20)); |
| 40 | + } |
26 | 41 | } |
27 | 42 | } |
0 commit comments