Cronjob Keeps Sending Multiple Emails
I got a problem on my Laravel project. I've been developing a website where users create complaints about brands. The problem is that I want to send the users a reminder email and notification after 3 days of creating their complaints. And I want to send this email once. That's why I checked if the reminder has been sent before. This code works fine on localhost and sends only one email and notification. But it keeps sending multiple emails and notifications (sometimes 40-50 ) in a minute on ubuntu server. The code works multiple times without executing codes down below. Does anyone know why I have this problem?
My code is below:
COMPLAINTREMIN开发者_StackOverflowDER.PHP:
protected $signature = 'complaints:reminder';
public function handle()
{
// $complaints = Complaints::with('author')->whereIn('status', ['now_active', 'answered'])->where('approved_at', '<=', Carbon::now()->subHour(72))->get();
$complaints = Complaints::with('author')->where('status', 'now_active')->where('member_id', 10)->get();
foreach($complaints as $complaint) {
$subject = "random subject";
$text = "randomtext";
$textPanel ="Text for notification panel" ;
if($complaint->is_reminder_sent == 0) {
$this->sendMailByZoho($complaint->author->email, $subject, $text);
$this->sendPanelNotification($complaint->author, $textPanel,'memberNewComplaint' ,'type' );
$complaint->update(['is_reminder_sent' => '1']);
}
}
return 0;
}
KERNEL.PHP:
protected function schedule(Schedule $schedule)
{
$schedule->command('complaints:reminder')->everyMinute();
}
CRONTAB:
-
-
-
-
- cd /path_to_my_project && php artisan schedule:run >> /dev/null 2>&1
-
-
-
$complaint->update(['is_reminder_sent' => '1']);
Is this line working?
I would have used:
$complaint->is_reminder_sent = 1;
$complaint->save();
精彩评论