Separate graphics for Azure webjob features?

Can I set up separate schedules for individual non-running features on the Azure website? I ask, because I have half a dozen separate tasks that I would like to run at different times of the day and at different intervals and do not want to create a separate project for each.

+5
source share
3 answers

Yes you can use TimerTriggerAttribute

Here is a sample code:

 public class Program { static void Main(string[] args) { JobHostConfiguration config = new JobHostConfiguration(); // Add Triggers for Timer Trigger. config.UseFiles(filesConfig); config.UseTimers(); JobHost host = new JobHost(config); host.RunAndBlock(); } // Function triggered by a timespan schedule every 15 sec. public static void TimerJob([TimerTrigger("00:00:15")] TimerInfo timerInfo, TextWriter log) { log.WriteLine("1st scheduled job fired!"); } // Function triggered by a timespan schedule every minute. public static void TimerJob([TimerTrigger("00:01:00")] TimerInfo timerInfo, TextWriter log) { log.WriteLine("2nd scheduled job fired!"); } } 

You can also use the CRON expression to indicate when to run the function:

Continuous WebJob with timer trigger and CRON expression

+7
source

You can write a regular old console application with an infinite loop that stops at the end of each iteration with Thread.Sleep (). Each time the cycle wakes up, it checks the schedule that it stores inside itself and calls all the functions that should be performed at this time. The schedule can be saved in app.config so you can change it without recompiling WebJob, just download the new app.config and restart it.

Or, if you prefer, you can omit the infinite loop and schedule the WebJob at a fixed interval, say every 30 minutes, and check its internal schedule every time it starts.

0
source

I ended up using Quartz.net with a continuous task to plan various activities internal to web work. It works very well.

0
source

Source: https://habr.com/ru/post/1216564/


All Articles