Scheduling
Schedule Orchestration and Analytic Execution
Scheduling the execution of an orchestration or an individual analytic can be done on time-based intervals.
REST APIs are provided for managing a scheduled analytic or orchestration execution (also called a job). Using these APIs you can perform the following actions.
- Create a job definition
- Retrieve job definitions
- Retrieve job history
- Update job definitions
- Delete existing jobs
When creating or updating a job, you can enable a job execution by setting the job state to Active. To disable a job, set the state to Inactive.
Task Roadmap: Scheduling a Job
A task roadmap provides the recommended order of steps to complete a process and serves as a planning guide. Use the following roadmap as a guide to schedule an analytic or orchestration execution.
You can schedule an orchestration or an individual analytic to be executed on time-based intervals using REST APIs. A scheduled analytic or orchestration execution is call a job
Task | Information | |
---|---|---|
1. | Understand how to find the URI values and to configure the REST headers for each API | See |
2. | Review what actions can be scheduled | See Schedule Orchestration and Analytic Execution |
3. | Ensure you have a dedicated OAuth2 client to execute your scheduled jobs | See
|
4. | Test that the dedicated OAuth2 client is set up correctly | See Validating an OAuth2 Client for Scheduler |
5. | Schedule the job | See Scheduling a Job |
Scheduling a Job
The following steps demonstrate how to schedule a job that will invoke an HTTP REST endpoint every 30 seconds.
Before You Begin
You must have the HTTP endpoint for the job you are going to schedule.
About This Task
In this example, it is assumed that the HTTP method is POST and REST endpoint is <JOB_EXECUTION_ENDPOINT>.
If a job fails after execution check its job history in the scheduler service. In the case where 25 jobs have failed, the job will be automatically suspended by the system.
There are five main parts in the request for scheduling a job.
Part | Header/Element | Description |
---|---|---|
Authorization with the scheduler service | "Authorization " and "Predix-Zone-Id " headers | These are the standard headers to enforce authorization for Predix services. For more information, see Configuring REST Request Headers. |
Authorization for job execution | "Refresh-Token-For-Job-Execution " header | (Optional) When a job is triggered, the scheduler makes a REST API call to the job execution endpoint configured in the job request body. If the job execution endpoint is secured by OAuth2, the scheduler requires an OAuth2 token to invoke the job execution endpoint successfully. Scheduler uses this refresh token to generate the OAuth2 access token. If this header is not set, scheduler will use "Client Credentials" grant type to generate an access token. |
Metadata of a job | "name ", "description ", and "state " elements | "name " is a required element. "state " can be "active " or "inactive ". "state " is set to "active " by default. |
Scheduling configuration of a job | "cron " element | Required in the request body. Configures when the job will be triggered. |
Execution configuration of a job | "executionRequest " element | Required in the request body. Configures how the job execution endpoint should be invoked when the job is triggered. |
Procedure
Managing Suspended Jobs
If a job fails after execution you should check its job history in the scheduler service. The job is automatically suspended by the system if there are 25 consecutive job failures, or if the refresh token has expired. In either case, verify the job's status and re-activate it by following the steps in this task.
Procedure
Job Execution Configuration Reference
Field | Mandatory | Allowed Values | Description |
---|---|---|---|
url | Yes | REST API endpoint to invoke when the job execution is triggered by the job scheduler. | |
httpMethod | Yes | GET , POST , HEAD , OPTIONS , PUT , PATCH , DELETE , TRACE | HTTP method |
httpHeaders | No | HTTP headers needed by the REST API endpoint | |
inputData | Input data for the REST API request |
Job Scheduling Configuration Reference
Field | Mandatory | Allowed Values | Allowed Special Characters | Notes |
---|---|---|---|---|
seconds | Yes | 0-59 | , - * / | |
minutes | Yes | 0-59 | , - * / | |
hours | Yes | 0-23 | , - * / | |
dayOfMonth | Yes | 1-31 | , - * ? / L W | Special character '?' can not be used in both dayOfMonth and dayOfWeek fields at same time.Example: To schedule a job for 15th day of the month, set |
months | Yes | 1-12 or JAN-DEC | , - * / | The allowed abbreviated month names are JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. |
dayOfWeek | Yes | 1-7 or SUN-SAT | , - * ? / L # | The allowed abbreviated names for the days are SUN, MON, TUE, WED, THU, FRI and SAT. Example: To schedule a job for 15th day of the month, set |
years | No (Default: empty) | empty, 1970-2099 | , - * / | |
timeZoneId | No (Default: UTC) | Java Time Zone ID |
Character | Description |
---|---|
',' | Used to specify a list of values. For example, setting months field to "JAN,MAY,SEP' means the month of January, May and September. |
'-' | Used to specify a list of values. For example, setting months field to 'JUN-AUG' means the month of June, July and August. |
'*' | Used to specify "all values". For example, '*' in seconds field it means every second. |
'?' | Used to specify "no special value". |
'L' |
|
'W' | Special character for dayOfMonth . Used to specify the weekday nearest to the given day. For example, '20W; specifies "nearest weekday to the 20th day of the month". A weekday is Monday to Friday. |
'#' | Special character in dayOfWeek . Used with a number before and a number after. For example, 'm#n' where 'm' specifies the day of the week and 'n' specifies the nth occurrence in the month. '3#2' specifies "the second Tuesday of the month" ('3' = "Tuesday" and '#2' = 'second one in the month"). |
For more information about these special characters, please see the CronTrigger Tutorial in Quartz documentation at http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.
For more information about available values for Java time zoneid
, please see Java documentation at http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html.