Continuous Azure web jobs may be used as subscribers to some external events (e.g. new item has been added to Azure storage queue). In opposite to scheduled based web jobs which are running by scheduler (you need to specify CRON expression for them) continuous web jobs are always running and react on events they are subscribed to.
When you scale your Azure app service on multiple instances (web jobs may run on different VMs in background) by default web jobs are also scaled i.e. they will run on all instances. However it is possible to change this behavior and run continuous web job as singleton only on 1 instance.
When create continuous web job in Azure portal there is Scale field which is by default set to Multi instance:
As tooltip says:
Multi-instance will scale your WebJob across all instances of your App Service plan, single instance will only keep a single copy of your WebJob running regardless of App Service plan instance count.
So during creation of web job we may set Scale = Single instance and Azure will create it as singleton.
If you don't want to rely on this setting which can be changed from UI you may add settings.job file with the following content:
{ "is_singleton": true }
to the root folder of your web job (the same folder which contains executable file of web job). In this case Azure will create web job as singleton even if Scale = Multi instance select is selected in UI. I.e. settings.job has priority over UI setting.
If you will check logs of continuous web job which was created using above method you should see something like that:
Status changed to Starting
WebJob singleton settings is True
WebJob singleton lock is acquired
Which will prove that job runs as singleton.
No comments:
Post a Comment