This sample demonstrates how to delay the execution of queue triggered Azure Functions. While the delay is wrapped by queue-triggered functions, internally, a delay can only be achieved by a Timer Trigger, only available in durable functions.
A queue-triggered function ScheduleDelayReceiveFromQueue
receives the a compound items from the queue, including the queue message to be sent to the desired queue, together with the desired time of execution or a given delay.
This information is used to execute ScheduleDelayOrchestrator
, which will start and await a DurableTimer
to achieve the delay.
After the delay, the orchestrator will start the ScheduleDelayWriteToQueue
activity function, which will send the message to the desired queue.
The delay mechanism is not perfect, as the delay is not guaranteed to be exact.
The DurableTimer
starts a second invocation of the orchestrator after the timer has run out.
However, the first execution of the orchestrator is still performed fully, but without any side effects.
Thus, log messages of the first (waiting) execution are still visible, even though the actual execution of the activity function is performed by the second execution of the orchestrator.
To circumvent this, the .IsReplaying
is replaying property can be used to check if the current execution is a replay of a previous execution.