Is it possible to set up separate schedules for individual non-triggered functions in an Azure webjob? I ask because I have half a dozen individual tasks I'd like to run at different times of the day and at different intervals and don't want to create a separate project for each.
To change the schedule, or to Modify the CRON value just use the App Service Editor to modify the WWWROOT/App_Data/jobs/triggered/YOUR_WEBJOB_NAME/settings. job file; By the time of writing, App Service Editor is still in preview but it will work.
Schedule a Function in Azure by Timer TriggerOne of the triggers for Azure Functions is the timer-trigger – allowing you to run a function on a schedule. With the timer trigger, you can use cron-expression to define when the function needs to run.
Webjobs run as background processes in the context of an App Service web app, API app, or mobile app whereas Functions run using a Classic/Dynamic App Service Plan.
Yes you can using the 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 a CRON expression to specify when to trigger the function:
Continuous WebJob with timer trigger and CRON expression
I ended up using Quartz.net with a continuous job for scheduling various activities internal to the web job. This has worked very well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With