laravel-pubsub-queue icon indicating copy to clipboard operation
laravel-pubsub-queue copied to clipboard

Better control on delayed execution of messages

Open anaspk opened this issue 4 years ago • 0 comments

Hi @kainxspirits ,

First of all, thanks a lot for sharing this Pubsub driver for Laravel Queues. It definitely saved me a decent amount of time since I didn't have to implement it myself.

I was looking at how the delayed messages are handled. I found here that when available_at attribute is set in future for a message, we just return immediately without acknowledging it. As a result, message gets picked again by worker after the ack deadline set on the pubsub subscription is passed. In my case, I have set the ack deadline on my pubsub subscription to the max allowed value i.e. 600s. Now I want to be able to execute messages with any custom delay value within this range like 10s, 1m, 2m etc. Current implementation doesn't allow this.

However, it is possible to do this as following:

  1. When available_at > time() , get the remaining seconds like remaining_time = available_at - time()
  2. Modify ack deadline of this specific message to be remaining_time.
  3. Now as soon as remaining_time has passed, Pubsub subscription will make this message available again, overriding the ack deadline set on the subscription itself.

I am going to submit a PR with this implementation. Please let me know if this sounds like a valid general use case and if you would like to merge it in?

anaspk avatar Sep 10 '20 16:09 anaspk