Skip to content
phstc edited this page Oct 26, 2014 · 11 revisions

Good news - you don't need to do anything to retry a message, SQS will handle that automatically for you. Basically do not delete sqs_msg.delete if you want to retry a message. The message will become available again when it reaches the visibility_timeout.

class MyWorker
  include Shoryuken::Worker

  shoryuken_options queue: 'default', delete: true

  def perform(sqs_msg, body)
    do_something(sqs_msg, body) # raises an exception
  end
end

The example above you make the message available again in case the do_something raises an exception. Be careful with the delete option, if it's sent to true it will auto delete the message in case of the worker doesn't raise an exception.

If you want to retry without raising exceptions, you could use something like that:

class MyWorker
  include Shoryuken::Worker

  shoryuken_options queue: 'default', delete: false

  def perform(sqs_msg, body)
    # do something
    sqs_msg.delete unless should_retry?(sqs_msg, body)
  end
end

Check the Dead Letter Queue documentation to prevent the message being processed forever.