When I go to configure a Schedule in the Azure management console, I'm only given the option of scheduling with an absolute end date/time (or never ending) and an interval.
So I can't, from this UI, schedule a job to every 30 minutes run every day from 8:00 AM to 6:00 PM only (i.e. don't run from 6:01 PM to 7:59 AM). Windows Task Manager and all other schedulers (cron, quartz) I've used before support the behaviour I want.
Is type of schedule supported at all in Azure, e.g. through the API or a hackish use of the Portal HTTP/JSON interfaces? I don't mind "hacking" the schedule once - it would beat embedding the schedule into the actual job script/application.
答案 0 :(得分:7)
您可以使用比Azure更灵活的内置调度。 您可以在此博文http://blog.amitapple.com/post/2015/06/scheduling-azure-webjobs/
中详细了解其工作原理 摘要:创建一个名为settings.job
的文件,其中包含以下json
{"schedule": "cron expression for the schedule"}
在你的情况下,#34的cron表达式从早上8点到下午6点每30分钟一次。将是0,30 8-18 * * *
所以你想要的JSON是
{"schedule": "0,30 8-18 * * *"}
请记住,这会使用本机的时区,默认为UTC。
答案 1 :(得分:0)
这是您需要在WebJob中实现的内容。我有一个类似的问题,我有WebJobs复杂的时间表。幸运的是,实施起来并不难。
这个snippit从UTC获取当地时间(我可以告诉东方),Azure的所有内容都设置为。然后检查它是星期六还是星期日,以及它是否退出(不确定是否需要)。然后检查它是在8AM之前还是在6PM之后以及它是否退出。如果它通过这两个条件,WebJob就会运行。
//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
希望这有帮助。