Does every instance of azure launch cron?

I am developing an ASP.NET application that will be uploaded to Azure. If I have multiple instances on Azure and I want to run the cron job, which will be necessary for my application. Then I just want to confirm whether this cron job will run only once or will each instance run this cron on its own?

For example: if I have 4 instances of the cloud service on Azure, and my application starts cron every day at 23:00. So, I just want to confirm whether this cron will be launched only once or will each instance run this cron on its own (i.e. Cron will be launched 4 times or can we say once for each instance)?

Please offer.

+8
c # cron scheduled-tasks azure
source share
4 answers

So far I have found 3 ways to do cron jobs, but they all require some level of control over multiple instances that can run tasks.

The options I have used so far are:

+4
source share

In your example, all 4 instances will try to run the cron job. If you want only one instance to run a task, you would need to implement some kind of locking mechanism. What people usually do is that each instance will try to acquire a 1-minute lease on one block. Only one case will be successful in acquiring a lease. You can put the logic that only the instance that can get the lease does this cron job.

+3
source share

As other users have said, there are many ways to do this. I am adding a few sentences. You have created a Cloude service web page or website. If the first, easiest way is to create also one working role (only one) and run tasks from there. This is the last one, you need an external β€œtrigger”: you can use Scheduler (from Aditi). You can get it from the Azure store (there is a free flank).

+1
source share

If the role (the Web / Worker / VM role) has several instances, this means that you received the same account for the Windows Server virtual machines (the version depends on the version of the guest OS that you configured). Each virtual machine will work with the same code in your application (for example, an ASP.NET web application), all requests for this role will be load balanced, and one of the virtual machines will break the request based on a circular policy.

So, if your cron job needs to be run only once, as Guarav said, you need a locking mechanism that allows one of your role instances to run it.

0
source share

All Articles