Run Azure Mobile Services Jobs on Demand
Have you ever wondered that in Windows Azure Management Portal you can run scheduled scripts on demand, but there is no documentation on how to do it yourself (at least )? I think I've checked every possible place and nothing. I've checked
azure command line help and nothing. In general you have a message like this: You can also use the Management Portal to run jobs on demand. and nothing more. But there is a good news! You can run your scheduled jobs on demand yourself! Finally I can run my integration tests without manually starting a scheduled job.
So how to run it?
It ended up that it is very easy, just undocumented. First of all you have to make a POST HTTP call to
https://<service name>.azure-mobile.net/jobs/<job name>, but this is not all. In addition you have to send two headers:
x-zumo-applicationwhich is set to your application key (this is the standard key)
x-zumo-masterwhich is set to you master key (which make sense as scheduled jobs should be run only by admins)
Both keys are available in Management Portal. Please remember that each job run is counted against your API calls limit! What is even more important that the job can be started from anywere, so there is no problem to use something like SetCronJob and run jobs every minute if you have to! AFAIK the current Windows Azure Scheduler is limited to no less than 15 minutes between jobs.
Additional benefit if you are interested. Chris Risner mentioned it on his own of //build presentation and I've similar experience. There is generally no limit about the run time of the job (in normal CRUD calls you have to respond in 30 seconds). It can run for 15 minutes or even for several hours (except Free tier, there it may be killed ealier, but it looks like it is free tier resources related).
If you have a bug in such long running job the only way to stop it is to make a configuration change in Management Portal to force a reload. Otherwise it may run for a long, long time.