Skip to content

Commit 4303b44

Browse files
committed
✨ mis en place des queues
1 parent 95730ec commit 4303b44

13 files changed

+113
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\User;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Mail;
8+
9+
class SendWelcomeMailToUsers extends Command
10+
{
11+
protected $signature = 'lcm:send-welcome-mails';
12+
13+
protected $description = 'Send mails to new registered users.';
14+
15+
public function handle(): void
16+
{
17+
foreach (User::all() as $user) {
18+
Mail::to($user)->queue(new \App\Mail\Welcome($user));
19+
}
20+
}
21+
}

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function schedule(Schedule $schedule)
2626
{
2727
// $schedule->command('media-library:delete-old-temporary-uploads')->daily();
2828
$schedule->command('lcm:delete-old-unverified-users')->daily();
29-
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
29+
$schedule->command('lcm:post-article-to-twitter')->everyFourHours();
3030
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();
3131
$schedule->command('lcm:send-unverified-mails')->weeklyOn(1, '8:00');
3232
$schedule->command('sitemap:generate')->daily();

app/Listeners/SendNewReplyNotification.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
use App\Events\ReplyWasCreated;
66
use App\Models\User;
77
use App\Notifications\NewReplyNotification;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Queue\InteractsWithQueue;
810

9-
class SendNewReplyNotification
11+
class SendNewReplyNotification implements ShouldQueue
1012
{
13+
use InteractsWithQueue;
14+
1115
public function handle(ReplyWasCreated $event)
1216
{
1317
/** @var \App\Models\Thread $thread */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Models\User;
6+
use Illuminate\Auth\Events\Registered;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Queue\InteractsWithQueue;
9+
use Illuminate\Support\Facades\Mail;
10+
11+
class SendWelcomeMailNotification implements ShouldQueue
12+
{
13+
use InteractsWithQueue;
14+
15+
/**
16+
* Handle the event.
17+
*
18+
* @param Registered $event
19+
* @return void
20+
*/
21+
public function handle(Registered $event)
22+
{
23+
/** @var User $user */
24+
$user = $event->user;
25+
26+
Mail::to($user)->queue(new \App\Mail\Welcome($user));
27+
}
28+
}

app/Mail/NewReplyEmail.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
use App\Models\Reply;
66
use App\Models\Subscribe;
7+
use Illuminate\Bus\Queueable;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
79
use Illuminate\Mail\Mailable;
810

9-
class NewReplyEmail extends Mailable
11+
class NewReplyEmail extends Mailable implements ShouldQueue
1012
{
13+
use Queueable;
14+
1115
/**
1216
* Create a new message instance.
1317
*

app/Mail/SendMailToUnVerifiedUsers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use App\Models\User;
66
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
78
use Illuminate\Mail\Mailable;
89
use Illuminate\Queue\SerializesModels;
910

10-
class SendMailToUnVerifiedUsers extends Mailable
11+
class SendMailToUnVerifiedUsers extends Mailable implements ShouldQueue
1112
{
1213
use Queueable, SerializesModels;
1314

app/Mail/Welcome.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88
use Illuminate\Mail\Mailable;
99
use Illuminate\Queue\SerializesModels;
1010

11-
class Welcome extends Mailable
11+
class Welcome extends Mailable implements ShouldQueue
1212
{
1313
use Queueable, SerializesModels;
1414

15-
/**
16-
* Create a new message instance.
17-
*
18-
* @return void
19-
*/
2015
public function __construct(public User $user)
2116
{
22-
//
2317
}
2418

2519
/**
@@ -30,7 +24,7 @@ public function __construct(public User $user)
3024
public function build()
3125
{
3226
return $this->from('arthur@laravel.cm', 'Arthur Monney')
33-
->subject(__('Bienvenue sur Laravel Cameroun'))
27+
->subject(__('Bienvenue sur Laravel Cameroun'))
3428
->markdown('emails.welcome');
3529
}
3630
}

app/Notifications/NewCommentNotification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
use App\Models\Reply;
77
use App\Models\Subscribe;
88
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
910
use Illuminate\Notifications\Messages\MailMessage;
1011
use Illuminate\Notifications\Notification;
1112

12-
class NewCommentNotification extends Notification
13+
class NewCommentNotification extends Notification implements ShouldQueue
1314
{
1415
use Queueable;
1516

app/Notifications/NewReplyNotification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
use App\Models\Reply;
77
use App\Models\Subscribe;
88
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
910
use Illuminate\Notifications\Notification;
1011

11-
class NewReplyNotification extends Notification
12+
class NewReplyNotification extends Notification implements ShouldQueue
1213
{
1314
use Queueable;
1415

app/Notifications/SendApprovedArticle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use App\Models\Article;
66
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
78
use Illuminate\Notifications\Messages\MailMessage;
89
use Illuminate\Notifications\Notification;
910

10-
class SendApprovedArticle extends Notification
11+
class SendApprovedArticle extends Notification implements ShouldQueue
1112
{
1213
use Queueable;
1314

app/Notifications/YouWereMentioned.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace App\Notifications;
44

55
use App\Models\Reply;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
68
use Illuminate\Notifications\Messages\MailMessage;
79
use Illuminate\Notifications\Notification;
810

9-
class YouWereMentioned extends Notification
11+
class YouWereMentioned extends Notification implements ShouldQueue
1012
{
13+
use Queueable;
14+
1115
public function __construct(public Reply $reply)
1216
{
1317
}

app/Providers/EventServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Listeners\SendNewCommentNotification;
1313
use App\Listeners\SendNewReplyNotification;
1414
use App\Listeners\SendNewThreadNotification;
15+
use App\Listeners\SendWelcomeMailNotification;
1516
use Illuminate\Auth\Events\Registered;
1617
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
1718
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -26,6 +27,7 @@ class EventServiceProvider extends ServiceProvider
2627
protected $listen = [
2728
Registered::class => [
2829
SendEmailVerificationNotification::class,
30+
SendWelcomeMailNotification::class,
2931
],
3032
ReplyWasCreated::class => [
3133
SendNewReplyNotification::class,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('jobs', function (Blueprint $table) {
17+
$table->bigIncrements('id');
18+
$table->string('queue')->index();
19+
$table->longText('payload');
20+
$table->unsignedTinyInteger('attempts');
21+
$table->unsignedInteger('reserved_at')->nullable();
22+
$table->unsignedInteger('available_at');
23+
$table->unsignedInteger('created_at');
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::dropIfExists('jobs');
35+
}
36+
};

0 commit comments

Comments
 (0)