Skip to content

Scheduled Job - Job Definition

Overview

This section shows how to create and manage Job Definition for the Scheduled Job application.

Steps

Job Definition

  1. Right click on the scheduled-job-project project and select New → Scheduled Job.
  2. Enter log.job for the name of the Scheduled Job.
  3. Right click on log.job and select Open With → Code Editor.
  4. Replace the content with the following definition:

    {
        "expression": "0/10 * * * * ?",
        "group": "defined",
        "handler": "scheduled-job-project/handler.mjs",
        "description": "Scheduled Log Job",
        "parameters": [
            {
                "name": "severity",
                "type": "choice",
                "defaultValue": "",
                "choices": "Info,Warning,Error",
                "description": "The log severity"
            },
            {
                "name": "message",
                "type": "string",
                "defaultValue": "",
                "description": "The log message"
            }
        ]
    }
    
  5. Double click on log.job to open it with the Job Editor.

    Job Definition

Save & Publish

Saving the file will trigger a Publish action, that would schedule the job. As defined by the expression (0/10 * * * * ?), the job handler would be executed each 10 seconds and data would be insterted into the LOG_EVENTS table.

Log Events Data

  1. Navigate to the Database Perspective to check that there are new records in the LOG_EVENTS table.
  2. You can notice in the LOG_TIMESTAMP column that the last records are 10 seconds apart each.

    Job Data

Manage Jobs

  1. Navigate to the Jobs Perspective to see a list of the Scheduled Jobs on the instance.
  2. Click on the Enable/Disable icon to stop the log Scheduled Job.

    Jobs Perspective

  3. Navigate to the Database Perspective to check that there are no new records in the LOG_EVENTS table after the job was disabled.

  4. Go back to the Jobs Perspective.
  5. Click on the Trigger icon and then on the Trigger button to start new Job Execution.

    Trigger Job

    Force Trigger

    This action would instantly trigger the Job Handler without respecting the Job Schedule Expression or whether the Job Schedule is enabled or disabled.

  6. Navigate back to the Database Perspective to check that there was a new record added in the LOG_EVENTS table after the job was disabled.

Summary

Tutorial Completed

After completing all steps in this tutorial, you would:

  • Have Scheduled Job.
  • New records in the LOG_EVENTS table.
  • Experience with the Jobs Perspective.

Note: The complete content of the Scheduled Job tutorial is available at: https://github.com/dirigiblelabs/tutorial-scheduled-job-project