Scheduling Azure WebJobs

Scheduled Azure WebJob Options

I had a need to understand the options for scheduling Azure WebJobs. I quickly found the Azure documentation article Run background tasks with WebJobs which provides two possible methods for scheduling the execution of a WebJob, CRON expression and the use of Azure Scheduler. Those options were a good start and I'd like to discuss my thoughts on them and present additional possibilities.

Option 1

For CRON expressions the article describes the use of a settings.job file. What's not clear in that article is where this file originates. It turns out its added to your WebJob when you create a Triggered, Scheduled WebJob through the Azure Portal.

Option 2

Use Visual Studio to manually add settings.job to a console app (be sure the file's Copy to output directory property is set to Copy always) and then deploy that app as a Run on Demand WebJob using VS publishing.

Option 3

The Azure WebJobs SDK provides yet another method of creating CRON driven WebJobs. This method utilizes the SDK's TimerTrigger and requires a Continous WebJob. The WebJob can be created using the Azure Portal or by VS publishing as long as it's Continuous.

TriggerTimer is an attribute applied to a method argument of type TimerInfo. Its constructor takes a CRON expression string. By convention this method is to be implemented in the Functions class of the console app to be deployed.

public class Functions
    public static void MyJob([TimerTrigger("0 * * * * *")]TimerInfo timer)
        // Do stuff
Options 1-3 Restrictions

Each of the CRON expression methods previously described requires the Azure App Service hosting the WebJob be Always On. This means that the App Service's scaling tier must be Basic (currently $55/month) or higher. For many user's legitimate WebJob use cases the cost/benefit ratio simply doesn't make sense at that monthly cost.

Option 4

Users who require a cheaper solution will likely need to employ the second option from the originally referenced article, i.e. using Azure Scheduler to trigger Azure WebJobs. In that scenario there's no restriction on App Service pricing tier, i.e. Free works, and the cost for Azure Scheduler is minimal. The downside is, of course, an increase in system complexity.