In order to process cleanup jobs, that will run for every 8 hours, currently we have implemented as :
- Create scheduled Job using Azure Scheduler that puts message in storage queue when it is triggered.
Implement client in such a way that it will poll continuously and process whenever it receives message. Sample implementation of client is :
while (!CancellationToken.Value.IsCancellationRequested) { var message = await client.GetMessageAsync(); if (message != null) { // process the message } }
But the problem is we are waiting indefinetly even we know that we will get messages only after 8hours and also as per documentation, every attempt to read message from queue will incur cost.
How to optimize this in such a way that listeners will be spawned up on the fly for every configurable time instead of continuous loop?