0

I'm using an Azure Functions Queue Trigger to read in a queue message and process work in Python. I have my batchSize parameter set to 1 to limit concurrency. In the Python code, I have an additional check to see if the work is ready to be processed as in:

if work is ready:
    do_work()
else:
    dequeue the message and try again

I want to dequeue the message if the work isn't ready to be processed and try again in one minute. I think I can achieve the retry by just setting visibilityTimeout to 00:01:00. But what is the best way to dequeue the message? Would it just be:

if work is ready:
    do_work()
else:
    raise Exception("work is not ready, dequeue the message")

Would this allow the message to be dequeued and picked up for a retry in one minute? This use case is fairly rare and I'm wondering if there is a better way because I'm not sure if I want to see the Error in my logs for this case.

Edit: is it possible to use initialVisibilityDelay in my Python QueueTrigger? This would eliminate the need for me to throw an exception if I could delay the visibility of my messages by one minute.

ddx
  • 469
  • 2
  • 9
  • 27

1 Answers1

0

is it possible to use initialVisibilityDelay in my Python QueueTrigger?

How are you putting your messages to the queue initially? If it's with the Azure Queue storage output binding, then I think you can't easily set the initial visibility delay.

You can however archieve what you want by using the queue's put_message function:

put_message(queue_name, content, visibility_timeout=None, time_to_live=None, timeout=None)

As you can see, it accepts the visibility_timeout parameter to make a message "active" after a specific delay, which is what you're after if I understood correctly.

Michał Żołnieruk
  • 2,095
  • 12
  • 20
  • I'm using an event grid subscription on Blob Created events. I'd prefer to use the event grid instead of creating a new Azure Function that uses `put_message()` because it would save resources – ddx Oct 28 '20 at 22:31