Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQS - Delivery Delay of 30 minutes

From the documentation of SQS, Max time delay we can configure for a message to hide from its consumers is 15 minutes - http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html

Suppose if I need to hide the messages for a day, what is the pattern? For eg. I want to mimic a daily cron for doing some action.

Thanks

like image 960
Arun Avanathan Avatar asked Aug 07 '15 15:08

Arun Avanathan


3 Answers

The simplest way to do this is as follows:

SQS.push_to_queue({perform_message_at : "Thursday November 2022"},delay: 15 mins)

Inside your worker

message = SQS.poll_messages
if message.perform_message_at > Time.now
   SQS.push_to_queue({perform_message_at : "Thursday November 
   2022"},delay:15 mins)
else
   process_message(message)
end

Basically push the message back to the queue with the maximum delay and only process it when its processing time is less than the current time.

HTH.

like image 123
Algorini Avatar answered Nov 13 '22 14:11

Algorini


Visibility timeout can do up to 12 hours. I think you can hack something together where you process a message but don't delete it and next time it is processed its been 12 hours. So a queue with one message and visibility timeout of 12 hours. That gets you a 12 hour cron.

like image 26
user2890463 Avatar answered Nov 13 '22 14:11

user2890463


Cloudwatch is likely a better way to do it. You can use a createEvent API with the timer, and have it trigger either a lambda function or an API call to whatever comes next.

Another way to do is to use the "wait" utility in an AWS step function.

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

In any case, unless you are extremely sure you will never need anything more than 15 minutes, the SQS backdoor to add the delay seems hacky.

like image 7
Badri V Avatar answered Nov 13 '22 14:11

Badri V