0

In order to process cleanup jobs, that will run for every 8 hours, currently we have implemented as :

  1. Create scheduled Job using Azure Scheduler that puts message in storage queue when it is triggered.
  2. 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?

  • Why don't you have your scheduled job to do the cleanup? See [scheduled web jobs](https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/#CreateScheduled). – mert Jul 22 '15 at 05:07

1 Answers1

1

You did not mention how is your client deployed, so I'm hoping one of the below strategies can help you optimize. If you client is deployed as Cloud Resource: You can use Azure Automation service to schedule start/stop of the cloud resource, for example: start the cloud service just before message appears in the queue and trigger shutdown once it is done.

If your client is deployed on premise: You can of course use Thread.Sleep to reduce the number of hits

Also consider Azure Service Bus which allows you to subscribe for messages/topics.

Sri Kanth
  • 476
  • 2
  • 14
  • Thanks for reply. Client is deployed as cloud resource. Azure service bus cannot be used because this stragegy can be used as fallback if service bus is not available. Also Automation cannot be used because same cloud service hosts different jobs which will create different listeners out of which only few are background which we shouldn't wait indefinetly. – P V M Raghunandan potti Jul 21 '15 at 06:47
  • OK. you can also try converting the composite cloud service which does different jobs into multiple independent microservices, which can later be deployed and scheduled independently using WebJobs/Automation/WebAPIs. – Sri Kanth Jul 22 '15 at 06:41
  • Micro services cannot be used as Service Fabric implementation is very far from our scope. – P V M Raghunandan potti Jul 24 '15 at 04:03