我有一个预定的工作,我希望每小时运行一次,所有这项工作都是选择没有取消订阅但尚未发送邮件的用户,然后将电子邮件排队等待发送。这一切都是在Amazon ElasticBeanstalk中的工作环境中完成的,当涉及到该部分时,一切正常。
每小时运行一次,电子邮件排队等候。然而,一旦他们排队等候,他们仍然在飞行中,并且实际上没有发送电子邮件。
如果我将预定作业更改为每分钟运行一次,那么一切正常并且电子邮件会被发送,但是由于某些原因,它们会被发送两次。
我不知道该在这里查看什么,因为worker实例上的laravel.log文件中没有任何内容。也没有任何内容写入我设置的日程文件以从预定命令输出。
这是我执行命令的代码。
protected function schedule(Schedule $schedule)
{
$schedule->command('ryno:send-email-batch')->hourly()->timezone('America/New_York')->sendOutputTo(storage_path() . '/logs/bulkmail.log');
}
这是正在执行的命令的代码
class SendBulkEmailBatch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ryno:send-email-batch';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send a batch of the emails';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$rows = User::where('welcomed', false)->where('unsubscribed', false)->take(600)->get();
if(count($rows) > 0) {
foreach ($rows as $row) {
// send email to the queue to be sent
Mail::queue('emails.welcome', [], function($message) use($row) {
$message->to($row->email);
$message->subject('Welcome!');
});
}
}
}
}
添加到队列的每个作业最终都在failed_jobs数据库表中,表明已达到最大尝试次数。有关为什么会发生这种情况的任何想法?