Skip to content

Commit 90b9b23

Browse files
committed
feat: update webhook job to handle save event to cache
1 parent b7312ec commit 90b9b23

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/Jobs/ProcessWebhookEvent.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@
22

33
namespace CSlant\GitHubProject\Jobs;
44

5+
use CSlant\GitHubProject\Constants\WebHookConstant;
6+
use Illuminate\Bus\Queueable;
57
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;
712

813
class ProcessWebhookEvent implements ShouldQueue
914
{
10-
use Queueable;
15+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
16+
17+
protected array $eventData;
1118

1219
/**
1320
* Create a new job instance.
21+
*
22+
* @param array $eventData
1423
*/
15-
public function __construct()
24+
public function __construct(array $eventData)
1625
{
17-
//
26+
$this->eventData = $eventData;
1827
}
1928

2029
/**
2130
* Execute the job.
2231
*/
23-
public function handle(): void
32+
public function handle()
2433
{
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+
}
2641
}
2742
}

0 commit comments

Comments
 (0)