2
votes

I'm creating an Azure webjob, and there is something that's not clear to me. I envisioned it would allow me to create a class (or actually console exe application), and a Main method.

My idea was that I would have multiple Public methods that could be triggered by the web job. For example. I might have a method Import and one called Process. Import might happen once a week, and Process would happen daily. Import could even potentially internally trigger Process, etc. I assumed I could just decorate this public methods with attributes that I could configure individually within the Azure portal.

Is this wishful thinking? I'm seeing a ton of examples where we do some initial configuration with Main and then have either a listener or just go directly into your processing code.

Is it possible to do what I am envisioning? The documentation is not exactly clear on this.

1
What kind of trigger are you looking for? schedule, manual, on queue message, on blob, continuous? - Amit Apple
I spent a lot of time reading today and developing code. I understand much more about WebJobs now. I've figured out how to do exactly what I want within WebJobs. I want two jobs, one will be on a timer that will do some processing. During processing, commands will get written to a message queue (blob) in which my second webjob will be running continuously and listening. It will process as needed. The first webjob is deployed and working, and now working on the second. - user1060500
Great seems like you figured it out. - Amit Apple
Does anyone have an answer to the original question though? Is it possible to expose multiple scheduled "jobs" (with different schedules) in a single job exe? - Brian Vallelunga
@BrianVallelunga I don't think so. For a scheduled WebJob, the schedule applies at the hosting app level. - Steven Rands

1 Answers

1
votes

With the latest version of the webjob SDK you can now run scheduled jobs in the same webjob using the TimerTriggerAttribute (see webjobs sdk extensions)

thess functions will be triggered at different time:

// Triggered every hours
public static void HourlyTimerJob([TimerTrigger("00:01:00")] TimerInfo timerInfo, TextWriter log)
{
    log.WriteLine("Scheduled job fired!");
}


// Triggered every minute
public static void MinutelyTimerJob([TimerTrigger("00:00:01")] TimerInfo timerInfo, TextWriter log)
{
    log.WriteLine("Scheduled job fired!");
}