mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-10 12:51:28 +00:00
136 - Refactoring for Robustness
This commit is contained in:
@@ -13,8 +13,15 @@ class AttendeeMessage extends Model
|
|||||||
return $this->belongsTo(Concert::class);
|
return $this->belongsTo(Concert::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function recipients()
|
public function orders()
|
||||||
{
|
{
|
||||||
return $this->concert->orders()->pluck('email');
|
return $this->concert->orders();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withChunkedRecipients($chunkSize, $callback)
|
||||||
|
{
|
||||||
|
$this->orders()->chunk($chunkSize, function ($orders) use ($callback) {
|
||||||
|
$callback($orders->pluck('email'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ class SendAttendeeMessage implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->attendeeMessage->recipients()->each(function ($recipient) {
|
$this->attendeeMessage->withChunkedRecipients(20, function ($recipients) {
|
||||||
Mail::to($recipient)->send(new AttendeeMessageEmail($this->attendeeMessage));
|
$recipients->each(function ($recipient) {
|
||||||
|
Mail::to($recipient)->queue(new AttendeeMessageEmail($this->attendeeMessage));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user