How to schedule a Triggered WebJob

Overview

A Triggered Web Job can be run on a schedule by including a settings.job file alongside it. This article explains the schedule format and then walks through creating a scheduled Web Job from start to finish.

Web Jobs are only available to sites running on a Reserved Cloud Server. On a Shared Cloud site the Web Jobs page reports that Web Jobs can only be configured for sites on a Reserved Cloud Server, and offers no Add button.

settings.job and the schedule property

A triggered Web Job may be run on a schedule using a settings.job file that contains a setting for the schedule property. The schedule property requires a CRON expression for a value and the file needs to be located in the same folder as your Web Job.

For Web Jobs, the CRON expression has six space-delimited values to represent:

[SECONDS] [MINUTES] [HOURS] [DAYS] [MONTHS] [DAY OF THE WEEK]

Each of the fields can have the following:

  • A specific value (1)
  • A range (1-10)
  • A comma-separated set of values (1,2,3)
  • All values
  • An interval (/5)
  • Or a combination of values (1,5-10)

NOTE: When the settings.job file is updated, the Web Job's schedule will automatically change.

Examples

Once per minute:

{
"schedule": "0 * * * * *"
}

Every 5 minutes starting at the top of the hour:

{
"schedule": "0 */5 * * * *"
}

Midnight during weekdays:

{
"schedule": "0 0 0 * * 1-5"
}

Scheduling a Triggered Web Job

Let's take a look at the steps required to create and deploy a triggered Web Job.

  1. Prepare your executable or script. If you don't have a pre-existing script, create a text file and then use or modify the following PowerShell script as a sample:
    <#
    Sample PowerShell Mailer
    #>
    $EmailFrom = "[email protected]"
    $EmailTo = "[email protected]"
    $Subject = "Daily Report"
    $Body = "Report details."
    $SMTPServer = "mail.YourSiteDomain.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "password");
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
  2. Save or rename your file as run.ps1.
  3. Create a new text document and then add the following schedule property:
    {
    "schedule": "0 */5 * * * *"
    }
  4. Save or rename your file as settings.job.
  5. Create a .zip file that contains your executable or script and the settings.job file. The upload is limited to 2 MB.
  6. Log in to the Everleap Control Panel at cp.everleap.com.
  7. From the top menu click Shared Sites.
  8. On the Shared Cloud Sites Overview page, click Manage next to the site where the Web Job will run.
  9. On the Site Overview page, find the General Information panel and click Manage on the Web Jobs row.
  10. Click the Add Web Job button.
  11. On the Add Web Jobform, use the following settings:
    • Type: Triggered
    • Web Job Name: user-defined
    • Zip File: click Choose File and select the .zip file
  12. Click the Add button to create the Web Job.
The Add Web Job form with Type set to Triggered, the Web Job Name field, and the Zip File field showing a 2 MB maximum

Verify it worked

From the Web Jobs page, click Manage for the Web Job that was created. You do not need to run it manually. After a successful execution you will see the status of the last run as well as the run history:

The management screen for a Triggered Web Job, showing Type, Last Status, a Run History table with Start, End, Status and Output Log columns, an Invoke Web Job box with a Run button, and a Delete Web Job button

On that screen you can also:

  • click View Log against any run to read its output log
  • run the job immediately using Invoke Web Job, optionally passing arguments
  • remove the job with Delete Web Job

Notes

  • The times in the run history are shown in UTC, not your local time zone.
  • Adding a Web Job also enables Always On for the site automatically. A scheduled job needs it, because a site that has been spun down for being idle is not running to trigger anything. See The Always On setting.
  • To change the schedule later, update settings.job and redeploy. The schedule changes automatically when the file is updated.

Related articles