ruby-shoryuken / shoryuken

A super efficient Amazon SQS thread based message processor for Ruby. This project is in MAINTENANCE MODE. Reach me out on Slack link on the description if you want to become a new maintainer.
Other
2.06k stars 280 forks source link

AWS SQS Message Stuck in Flight #716

Closed vipulvkp closed 2 years ago

vipulvkp commented 2 years ago

Hi,

I have a AWS SQS FIFO queue configured with visiblity timeout set to 30 seconds. Below is my shoryuken.yml file

concurrency: 1
pidfile: tmp/shoryuken.pid
logfile: log/shoryuken.log.<%= Time.now.strftime('%Y%m%d') %>
queues:
  - ["daily_queue.fifo"]

I have defined one worker which listens to the queue and also auto_delete is set to true. As we can see, the processing is nothing but simply printing a message.

class DailyWorker
  include Shoryuken::Worker
  shoryuken_options queue: 'daily_queue.fifo', auto_delete: true
  def perform(message)
    p "ALL GOOD"
  end
end

Also, I have enabled long polling in config/initializers/shoryuken.rb as below

Shoryuken.sqs_client = Aws::SQS::Client.new(region: Settings.aws.region)
Shoryuken.sqs_client_receive_message_opts = { wait_time_seconds: 5, max_number_of_messages: 10 }

Before I start my shoryuken process , I add one message to the SQS Queue using SQS AWS Console. After starting shoryuken worker, the SQS message goes from Messages Available to Messages in Flight and it is stuck in flight for ever. Please Note, AWS SQS message has a unique message group id and a unique message deduplication id. And there is only one message in the queue

I read the documentation, In Flight status is when the consumer has received the message and has not deleted it yet. I wonder what could go wrong with my shoryuken worker as its doing a simple print statement and also auto_delete is set to true.

matt-taylor commented 2 years ago

Hey @vipulvkp When using include Shoryuken::Worker (as opposed to active Job), the perform method expects two params (source code.

Based on your code, the Retry policy will add a visibility timeout to the message in order to attempt the message at a later date.

Can you try to changing your code to:

class DailyWorker
  include Shoryuken::Worker
  shoryuken_options queue: 'daily_queue.fifo', auto_delete: true
  def perform(sqs_msg, name) # With two arguments
    p "ALL GOOD"
  end
en
vipulvkp commented 2 years ago

@matt-taylor Thank you so much. Yes after suggesting your change of making def perform(sqs_msg, name) the control went inside worker call and yes the print message was recorded.