Azure WebJob / Scheduler every 30 minutes from 8 am to 6 pm?

When I go to set up a schedule in the Azure Management Console, I am only presented with a scheduling option with an absolute end date / time (or infinite end) and an interval.

enter image description here

So I cannot, from this UI, schedule a job every 30 minutes every day from 8:00 AM to 6:00 PM (i.e. not run from 6:01 PM to 7:59 AM). Windows Task Manager and all other schedulers (cron, quartz) that I used before supporting the behavior I want.

Is the schedule type supported in Azure, for example. via API or hacky use of HTTP / JSON portal interfaces? I don't mind "hacking" the schedule once - it will beat the embedding of the schedule in the current script / application job.

+3


source to share


2 answers


You can use inline scheduling, which is more flexible than Azure. You can read more about how this works from this blog post http://blog.amitapple.com/post/2015/06/scheduling-azure-webjobs/

Summary: create a file named settings.job

which contains the following json snippet

{"schedule": "cron expression for the schedule"}

      

in your case, the cron expression for "every 30 minutes from 8 am to 6 pm" would be 0,30 8-18 * * *



so you need JSON

{"schedule": "0,30 8-18 * * *"}

      

Remember, the default is the machine's time zone, which is UTC by default.

+7


source


This is what you need to implement in your WebJob. I have the same problem that I have WebJobs with complex schedules. Fortunately, this is not difficult to implement.

This snippet gets your local time (Eastern from what I can tell) from UTC, which all Azure is configured for. Then it checks if it is Saturday or Sunday and if it exits (not sure if you need this). He then checks to see if he is logged out before 8 am or after 6 pm. If it passes both of these conditions, the WebJob is launched.



        //Get current time, adjust 4 hours to convert UTC to Eastern Time
        DateTime dt = DateTime.Now.AddHours(-4);

        //This job should only run Monday - Friday from 8am to 6pm Eastern Time.
        if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday) return;
        if (dt.Hour < 8 || dt.Hour > 16) return;

        //Go run WebJob

      

Hope it helps.

0


source







All Articles