// Консольная команда
$mailingList = MailingList::find(1);
dispatch(new SendDailyNewsletter($mailingList));
//SendDailyNewsletter
namespace App\Jobs;
use App\Entity\Subscription\MailingList;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Mail;
class SendDailyNewsletter implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $mailing_list;
public function __construct(MailingList $mailingList)
{
$this->mailing_list = $mailingList;
}
public function handle()
{
$subscriptions = DB::table('mail as m')->select(['m.email'])->where('m.id', $this->mailing_list->id)->get();
$subscriptions->each(function ($subscription) {
logger($subscription->email);
});
$subscriptions->each(function ($subscription) {
logger('+');
Redis::throttle('key')->allow(1)->every(5)->then(function () use ($subscription) {
logger($subscription->email);
//Mail::to($subscription->email)->queue(new DailyNewsletterMail($subscription->name));
}, function () {
return $this->release(5);
});
});
}
}
Делаю рассылкку через сайт. Для лимита решил использовать очереди и redis::throttle. Подскажите, почему некоторые данные скрипт пропускает?
// foreach тут весь список
[2019-06-05 13:24:30] local.DEBUG: korwru@example.com
[2019-06-05 13:24:30] local.DEBUG: test@example.com
[2019-06-05 13:24:30] local.DEBUG: jackson33@example.com
[2019-06-05 13:24:30] local.DEBUG: hollie.emmerich@example.com
[2019-06-05 13:24:30] local.DEBUG: nbrakus@example.com
[2019-06-05 13:24:30] local.DEBUG: estrella.christiansen@example.com
[2019-06-05 13:24:30] local.DEBUG: elinor.frami@example.com
//Redis::throttle часть позиций пропускает...
[2019-06-05 13:24:30] local.DEBUG: +
[2019-06-05 13:24:30] local.DEBUG: korwru@example.com
[2019-06-05 13:24:30] local.DEBUG: +
[2019-06-05 13:24:33] local.DEBUG: +
[2019-06-05 13:24:35] local.DEBUG: jackson33@example.com
[2019-06-05 13:24:35] local.DEBUG: +
[2019-06-05 13:24:38] local.DEBUG: +
[2019-06-05 13:24:40] local.DEBUG: nbrakus@example.com
[2019-06-05 13:24:40] local.DEBUG: +
[2019-06-05 13:24:43] local.DEBUG: +