简体   繁体   English

当消息发送回SQS时,Laravel队列工作程序作业失败

[英]Laravel queue worker jobs fail when messages are sent back to SQS

I have set up my Laravel application to retrieve messages from an SQS queue. 我已经设置了Laravel应用程序来从SQS队列中检索消息。 Everything works fine during normal operation: Messages are added to the queue when a queueable job is dispatched, and the queue worker grabs the message from SQS and runs the job successfully. 在正常操作期间一切正常:在调度可排队作业时,消息将添加到队列中,队列工作程序从SQS获取消息并成功运行作业。

However, I run into problems whenever I use the "View Messages" feature in the SQS web console. 但是,每当我使用SQS Web控制台中的“查看消息”功能时,我都会遇到问题。 Here are the steps to reproduce: 以下是重现的步骤:

  • Go into the SQS web console 进入SQS Web控制台
  • Select the queue 选择队列
  • Run "View Messages" to get a live view of messages coming in 运行“查看消息”以获取有关消息的实时视图
  • After a while, stop polling 过了一会儿,停止投票
  • Messages that were being intercepted are now released 被截获的消息现在已被释放
  • Queue worker grabs the messages but they all end up as failed jobs 队列工作者抓取消息,但它们最终都是失败的作业
  • Run artisan queue:retry all 运行工匠队列:重试所有
  • Failed jobs now run successfully 现在失败的作业成功运行

Why is this happening? 为什么会这样? I'm running Laravel 5.2.41 on PHP 5.6. 我在PHP 5.6上运行Laravel 5.2.41。

I figured out what was happening: 我弄清楚发生了什么:

  • When messages are "intercepted" to be shown in the live view, they are taken out of the queue. 当消息被“拦截”以在实时视图中显示时,它们将从队列中取出。
  • When you close the live view, the messages are re-added to the queue. 关闭实时视图时,会将消息重新添加到队列中。 The message metadata is then updated with the number of times the message has been received. 然后根据消息的接收次数更新消息元数据。
  • Since my queue worker was set to only retry once, then at this point the message has exceeded the number of retries (aka times received) and it marks the job as failed. 由于我的队列工作程序设置为仅重试一次,因此此时消息已超过重试次数(也就是收到的次数),并且它将作业标记为失败。

To solve this, I added an extra retry "buffer" to my queue workers: 为了解决这个问题,我在队列工作者中添加了一个额外的重试“缓冲区”:

php artisan queue:work redis --tries=3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM