我有1500多个用户,并通过邮件和数据库向他们发送通知,以提醒他们每周使用cron和超级用户提醒一些事情。
我的队列配置:
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
我的主管配置:
[program:run-cron]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/projectName/artisan queue:work database --sleep=3 --tries=3 --timeout=50 --queue=default,reminder
autostart=true
autorestart=true
user=www-data
numprocs=6
redirect_stderr=true
stdout_logfile=/var/www/html/projectName/storage/logs/supervisor.log
通知代码:
class UserReminderNotification extends Notification implements ShouldQueue
{
use Queueable;
public $job,$days,$settings;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->queue="reminder";
$this->user = $data['user'];
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return array('database','mail');
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$title = 'Reminder Title';
return (new MailMessage)
->subject($title)
->view(
'user.reminder',
array(
'user' => $this->user,
)
);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'type' => 'user',
'name' => $this->user->name,
'messsage' => 'Reminder message';
];
}
}
错误我在失败的工作中遇到了什么
PDOException:SQLSTATE [23000]:违反完整性约束:1062密钥“ PRIMARY”的条目“ 3fee38fc-8e1f-4212-9e96-12c4af1510c4”重复
我所缺少的。如您所见,retry_after已经大于--timeout。
我认为邮件失败了,当主管再次尝试时,它再次为该数据库通知输入条目。奇怪的是,这并不能全部解决。