-
-
Notifications
You must be signed in to change notification settings - Fork 289
Retrying a message
phstc edited this page Nov 1, 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', auto_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 auto_delete option, if it's set to true
, Shoryuken 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', auto_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.