How to schedule a Triggered WebJob

settings.job and the schedule property

A triggered WebJob 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 WebJob. For WebJobs, 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 WebJob'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 WebJob

Let's take a look at the steps required to create and deploy a triggered WebJob.
  1. Prepare your executable/script. If you don't have a pre-exiting script, create a text file and then use/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/rename your file as run.ps1
  3. Create a new text document and then add the following schedule property:

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

     
  4. Save/rename your file as settings.job
  5. Create a .zip file that contains your executable/script and the settings.job file.
  6. Sign-in to the Everleap control panel and then navigate to the following:
    • Sites
    • Click Manage for your site where the WebJob will run
    • Click Manage for Web Jobs
  7. Click the Add Web Job button
  8. From the Web Jobs menu, use the following settings:
    • Type: Triggered
    • Web Job Name: User-defined
    • Click the Choose File button and then upload the .zip file
    • Next, click the Add button to create the WebJob.
       
  9. From the Web Jobs page, click Manage for the WebJob that was created.
  10. You do not need to manually execute the WebJob and after successful execution, you will see the status of the last execution as well as the run history: