Skip to content

Commit 9e8f958

Browse files
committed
feat: update cache handling in webhook processing
1 parent 90b9b23 commit 9e8f958

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

config/github-project.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
'enable_status_comment' => env('GITHUB_PROJECT_ENABLE_STATUS_COMMENT', false),
1616

1717
'is_queue_enabled' => env('GITHUB_PROJECT_QUEUE_ENABLED', false),
18+
'comment_aggregation_cache_key' => env('GITHUB_PROJECT_COMMENT_AGGREGATION_CACHE_KEY', 'github-project-comment-aggregation'),
19+
'comment_aggregation_time' => env('GITHUB_PROJECT_COMMENT_AGGREGATION_TIME', 20),
1820
];

src/Jobs/ProcessWebhookEvent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CSlant\GitHubProject\Jobs;
44

5-
use CSlant\GitHubProject\Constants\WebHookConstant;
65
use Illuminate\Bus\Queueable;
76
use Illuminate\Contracts\Queue\ShouldQueue;
87
use Illuminate\Foundation\Bus\Dispatchable;
@@ -31,12 +30,15 @@ public function __construct(array $eventData)
3130
*/
3231
public function handle()
3332
{
34-
$events = Cache::get(WebHookConstant::WEBHOOK_CACHE_NAME, []);
33+
$commentAggregationCacheKey = (string) config('github-project.comment_aggregation_cache_key');
34+
$commentAggregationTime = (int) config('github-project.comment_aggregation_time');
35+
36+
$events = Cache::get($commentAggregationCacheKey, []);
3537
$events[] = $this->eventData;
36-
Cache::put(WebHookConstant::WEBHOOK_CACHE_NAME, $events, now()->addSeconds(20));
38+
Cache::put($commentAggregationCacheKey, $events, now()->addSeconds($commentAggregationTime));
3739

3840
if (count($events) === 1) {
39-
ProcessAggregatedEvents::dispatch()->delay(now()->addSeconds(20));
41+
ProcessAggregatedEvents::dispatch()->delay(now()->addSeconds($commentAggregationTime));
4042
}
4143
}
4244
}

0 commit comments

Comments
 (0)