Skip to content

Commit f2afc5c

Browse files
committed
Configures queue retries and timeout for the digest email job.
Signed-off-by: Ismoiljon Umarov <hs.umarov21@gmail.com>
1 parent 895665d commit f2afc5c

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

app/Jobs/SendPostDigestEmail.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
<?php
2+
23
namespace App\Jobs;
34

45
use App\Mail\NewPostsNotification;
56
use App\Models\Post;
67
use App\Models\User;
78
use Carbon\Carbon;
8-
use Exception;
99
use Illuminate\Bus\Queueable;
1010
use Illuminate\Contracts\Queue\ShouldQueue;
1111
use Illuminate\Foundation\Bus\Dispatchable;
1212
use Illuminate\Queue\InteractsWithQueue;
1313
use Illuminate\Queue\SerializesModels;
14-
use Illuminate\Support\Facades\Log;
1514
use Illuminate\Support\Facades\Mail;
1615

1716
class SendPostDigestEmail implements ShouldQueue
1817
{
1918
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2019

20+
public int $tries = 3;
21+
public int $timeout = 30;
22+
public array $backoff = [60, 180, 300];
23+
2124
public function __construct(public User $user)
2225
{
2326
}
2427

2528
public function handle(): void
2629
{
27-
$user = User::find($this->user->id);
30+
$user = $this->user->fresh();
2831

2932
if (!$user || !$user->receives_notifications) {
30-
Log::info("Skipping post digest for user {$this->user->id} because they have unsubscribed or were deleted.");
3133
return;
3234
}
3335

@@ -41,14 +43,9 @@ public function handle(): void
4143
$mainPost = $newPosts->sortByDesc('total_votes')->first();
4244
$gridPosts = $newPosts->where('id', '!=', $mainPost->id)->take(4);
4345

44-
try {
45-
Mail::to($user)->send(new NewPostsNotification($user, $mainPost, $gridPosts));
46+
Mail::to($user)->send(new NewPostsNotification($user, $mainPost, $gridPosts));
4647

47-
$user->last_notified_at = Carbon::now();
48-
$user->save();
49-
} catch (Exception $e) {
50-
Log::error("Failed to queue post digest for user {$user->id}: " . $e->getMessage());
51-
$this->release(300);
52-
}
48+
$user->last_notified_at = Carbon::now();
49+
$user->save();
5350
}
5451
}

0 commit comments

Comments
 (0)