Answer the question
In order to leave comments, you need to log in
How to implement a delay when sending emails via Redis::throttle?
// Консольная команда
$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);
});
});
}
}
// foreach тут весь список
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: [email protected]
//Redis::throttle часть позиций пропускает...
[2019-06-05 13:24:30] local.DEBUG: +
[2019-06-05 13:24:30] local.DEBUG: [email protected]
[2019-06-05 13:24:30] local.DEBUG: +
[2019-06-05 13:24:33] local.DEBUG: +
[2019-06-05 13:24:35] local.DEBUG: [email protected]
[2019-06-05 13:24:35] local.DEBUG: +
[2019-06-05 13:24:38] local.DEBUG: +
[2019-06-05 13:24:40] local.DEBUG: [email protected]
[2019-06-05 13:24:40] local.DEBUG: +
[2019-06-05 13:24:43] local.DEBUG: +
Answer the question
In order to leave comments, you need to log in
In the sense of just adding 1 month to some date?
$date = '2017-07-04';
$dateAt = strtotime('+1 MONTH', strtotime($date));
$newDate = date('Y-m-d', $dateAt);
echo $newDate;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question