Skip to content

Commit ed065ab

Browse files
committed
refactor: simplify ProcessAggregatedEvents and ProcessWebhookEvent classes by removing unnecessary logging and GitHub service dependency injection
1 parent 815b5cd commit ed065ab

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

src/Jobs/ProcessAggregatedEvents.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Queue\InteractsWithQueue;
1010
use Illuminate\Queue\SerializesModels;
1111
use Illuminate\Support\Facades\Cache;
12-
use Illuminate\Support\Facades\Log;
1312

1413
class ProcessAggregatedEvents implements ShouldQueue
1514
{
@@ -20,15 +19,12 @@ class ProcessAggregatedEvents implements ShouldQueue
2019

2120
protected string $nodeId;
2221

23-
protected GithubService $githubService;
24-
2522
/**
2623
* Create a new job instance.
2724
*/
28-
public function __construct(string $nodeId, GithubService $githubService)
25+
public function __construct(string $nodeId)
2926
{
3027
$this->nodeId = $nodeId;
31-
$this->githubService = $githubService;
3228
}
3329

3430
/**
@@ -41,19 +37,19 @@ public function handle(): void
4137
/** @var array<string, mixed> $eventMessages */
4238
$eventMessages = Cache::pull($commentAggregationCacheKey, []);
4339

44-
Log::info('ProcessAggregatedEvents: Event message: '.json_encode($eventMessages));
4540
$message = $this->aggregateMessages($eventMessages);
41+
$author = Cache::pull($commentAggregationCacheKey.'_author', []);
42+
4643
Cache::forget($commentAggregationCacheKey);
47-
$author = Cache::pull($commentAggregationCacheKey.'_author', '');
44+
Cache::forget($commentAggregationCacheKey.'_author');
4845

49-
Log::info('ProcessAggregatedEvents: Author: '.$author);
5046
$message .= '\n\n'.view(
5147
'github-project::md.shared.author',
5248
['name' => $author['name'], 'html_url' => $author['html_url']]
5349
)->render();
5450

55-
Log::info('ProcessAggregatedEvents: Message: '.$message);
56-
$this->githubService->commentOnNode($this->nodeId, $message);
51+
$githubService = new GithubService();
52+
$githubService->commentOnNode($this->nodeId, $message);
5753
}
5854

5955
/**

src/Jobs/ProcessWebhookEvent.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Queue\InteractsWithQueue;
99
use Illuminate\Queue\SerializesModels;
1010
use Illuminate\Support\Facades\Cache;
11-
use Illuminate\Support\Facades\Log;
1211

1312
class ProcessWebhookEvent implements ShouldQueue
1413
{
@@ -44,7 +43,7 @@ public function handle(): void
4443
$eventMessages = (array) Cache::get($commentAggregationCacheKey, []);
4544
$eventMessages[] = view('github-project::md.shared.content', ['payload' => $this->eventData])->render();
4645

47-
Cache::put($commentAggregationCacheKey, $eventMessages, now()->addSeconds($commentAggregationTime));
46+
Cache::put($commentAggregationCacheKey, $eventMessages, now()->addSeconds($commentAggregationTime + 3));
4847

4948
if (!Cache::has($commentAggregationCacheKey.'_author')) {
5049
Cache::put(
@@ -53,12 +52,10 @@ public function handle(): void
5352
'name' => $this->eventData['sender']['login'],
5453
'html_url' => $this->eventData['sender']['html_url'],
5554
],
56-
now()->addSeconds($commentAggregationTime)
55+
now()->addSeconds($commentAggregationTime + 3)
5756
);
5857
}
59-
Log::info('Event message count: '.count($eventMessages));
60-
Log::info('Event message: '.json_encode($eventMessages));
61-
Log::info('Event author: '.json_encode(Cache::get($commentAggregationCacheKey.'_author')));
58+
6259
if (count($eventMessages) === 1) {
6360
ProcessAggregatedEvents::dispatch($nodeId)->delay(now()->addSeconds($commentAggregationTime));
6461
}

0 commit comments

Comments
 (0)