我一直在开发一个用户投诉品牌的网站。问题是,我想在用户投诉3天后向他们发送提醒邮件和通知。这封邮件我想发一次。这就是为什么我检查了提醒是否以前发送过。
此代码在本地主机上运行良好,并且只发送一封电子邮件和通知。但在Ubuntu服务器上,它会在一分钟内发送多封邮件和通知(有时是40-50封)。代码多次工作而不执行下面的代码。有人知道我为什么有这个问题吗?
COMPLAINTREMINDER.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();
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']);
线路正常吗?
我会用:
$complaint->is_reminder_sent = 1;
$complaint->save();
我解决了这个问题。更新cron对我有效。