Scheduling a Job Using REST API
Learn how to manage migration job schedules using the DryvIQ REST API.
Table of Contents
Overview
A job schedule allows you to control when the job runs. The schedule manages job runs for you, so you don't have to execute them manually. The schedule can be set to determine both how often a job runs and when a job should stop running (also called the job stop policy). You also have the option to edit schedules for jobs. When defining the mode of your job, you have the following options.
Mode | Description | Code |
---|---|---|
ad-hoc | The job will not run until manually triggered. The job status will be "completed" when the job finishes the run. |
"schedule": { "mode": "ad-hoc" } |
auto | The job will be added to the job queue and run when a there is an available spot. The job will then run every 15 minutes after the initial run. |
"schedule": { "mode": "auto" } |
manual | The job will not run until manually triggered. |
"schedule": { "mode": "manual" } |
Additional Auto Scheduling Options
For auto, you can add additional scheduling options to define the job schedule. The table lists the options individually and identifies the code formatting for each option. However, options can be used in combination. See the Examples sections for code samples using multiple schedule options.
Option | Description | Values | Code |
---|---|---|---|
days | Sets the day(s) the job should run. The default value is "everyday." | everyday, weekdays, weekends, monday, tuesday, wednesday, thursday, friday, saturday, sunday | "days": "weekends", |
start_date | Sets the date to start running the job. Date values must be in Unix/Epoch timestamp format. For example, August 21, 2019 = 1566360000 | "start_date": "1523025357", | |
end_date | Sets the day to stop running the job. Date values must be in Unix/Epoch timestamp format. For example, August 21, 2019 = 1566360000 | "end": "1567123200", | |
repeat_count |
Sets the maximum number of times the job runs in one day. This option cannot be used with run_at. |
"repeat_count": 0, | |
repeat_interval |
Sets the time interval, from the last start time, from which to start the next run of the job. This option is set in milliseconds (ms). This option cannot be used with run_at. |
900000 is the default value (15 minutes). |
"repeat_interval": { "value": 900000, "unit": "ms" |
start_window |
Sets the time of day to start the job execution. Hour values must be 24 HR format. For example, 4:00 PM = 16:00
|
hr, min, sec, ms |
"start_window": { "hr": 8, "min": 0, "sec": 0, "ms": 0 |
end_window |
Sets the time of day the last job execution should run. Hour values must be 24 HR format. For example, 4:00 PM = 16:00 This option is used in combination with the start_window when you want the job to run withing a set time frame. This option cannot be used with run_at.
Note that a scheduled job will not run if the last run time for the job equals the “end_window” set in the job schedule. For example, if you schedule a job to run every 15 minutes starting at 1:00 PM and ending at 1:30 PM, the job will run at 1:00 PM and then at the scheduled 15-minute increment. If the next run time calculated for the job is 1:30 PM (the same as the “end_window” set for the job), the job will not be run again at 1:30 PM. |
hr, min, sec, ms |
"end_window": { "hr": 21, "min": 0, "ms": 0, "sec": 0 |
max_execution | Sets the maximum amount of time the job can run. Once the job hits this maximum, it stops. This option uses a unit and value. |
Acceptable units are: d, h, m, ms, ns, s, us |
"max_execution": { "unit": "d", "value": 1 |
run_at |
Sets the time of day to start the job execution.
|
hr, min, sec, ms |
"run_at": { "hr": 8, "min": 0, "sec": 0, "ms": 0 |
Examples
The examples below show how to use the various "auto" options in combination.
Defined Days with Start and End Windows
The following example shows a schedule that uses the following options:
- Days: Only on weekends
- End Date: April 6, 2018 GMT (1523025357 is Unix Epoch format)
- Start Window: 8:00 AM GMT
- End Window: 8:00 PM GMT
- Interval: Every 15 minutes (The default interval will be used since no other interval is included.)
"schedule": {
"mode": "auto",
"days": "weekends",
"end_date": "1523025357",
"start_window": {
"hr": 8,
"min": 0,
"sec": 0,
"ms": 0
},
"end_window": {
"hr": 20,
"min": 0,
"sec": 0,
"ms": 0
}
}
Max Executions
The following example shows a schedule that uses the following options:
- Max Execution: 1 day (The job will stop if the execution is running longer than 1 day.)
- Interval: Every 15 minutes (The default interval will be used since no other interval is included.)
"schedule": {
"mode": "auto",
"max_execution": {
"unit": "d",
"value": 1
}
}
Run at a Specific Time
The following example shows a schedule that uses the following options:
- Days: Mondays
- Run at: 8:00 AM GMT
- Interval: Every 15 minutes (The default interval will be used since no other interval is included.)
"schedule": {
"mode": "auto",
"days": "monday",
"run_at": {
"hr": 8,
"min": 0,
"sec": 0,
"ms": 0
}
}
Run on a Specific Date at a Specific Time
The following example shows a schedule that uses the following options:
- Start Date: April 6, 2018 at 2:35 PM GMT (1523025357 in Unix Epoch format)
- Start Window: Each day, the job starts running at 8:00 AM GMT and runs every 15 minutes thereafter. (See interval below.)
- Interval: Every 15 minutes (The default interval will be used since no other interval is included.)
"schedule": {
"mode": "auto",
"start_date": "1523025357",
"start_window": {
"hr": 8,
"min": 0,
"sec": 0,
"ms": 0
}
}
Run Every 15 Minutes Indefinitely
The following example shows a schedule that uses the following options:
- Repeat Interval: Every 15 minutes, with no scheduled stop. The next job run will start 15 minutes after the last run completes.
"schedule": {
"mode": "auto",
"repeat_interval": {
"value": 900000,
"unit": "ms"
}
}
Run Every 5 Minutes Indefinitely
The following example shows a schedule that uses the following options:
- Repeat Interval: Every 5 minutes, with no scheduled stop. The next job run will start 5 minutes after the last run completes.
"schedule": {
"mode": "auto",
"repeat_interval": {
"value": 300000,
"unit": "ms"
}
}
Run Hourly Every Day Within a Time Frame
The following example shows a schedule that uses the following options:
- Days: Every day
- Repeat Interval: Every hour. The next job run will be 1 hour after the last run completes.
- Start Window: Start at 6:00 AM GMT
- End Window: End at 9:00 PM GMT
- The job will run indefinitely since no stop schedule is set.
},
"schedule": {
"mode": "auto",
"days": "everyday",
"repeat_interval": {
"value": 3600000,
"unit": "ms"
},
"start_window": {
"hr": 6,
"min": 0,
"ms": 0,
"sec": 0
},
"end_window": {
"hr": 21,
"min": 0,
"ms": 0,
"sec": 0
}
}
}
Run Every day, Every Hour, Within a Specified Time Frame for a Given Date Range
The following example shows a schedule that uses the following options:
- Days: Every day
- Repeat Interval: Every hour. The next job run will be 1 hour after the last run completes.
- Start Date: August 21, 2019 12:00:00 AM GMT
- End Date: August 21, 2020 12:00:00 AM GMT
- Start Window: 6:00 AM GMT
- End Window: 9:00 PM GMT
},
"schedule": {
"mode": "auto",
"days": "everyday",
"repeat_interval": {
"value": 3600000,
"unit": "ms"
},
"start_date": "1566345600",
"start_window": {
"hr": 6,
"min": 0,
"ms": 0,
"sec": 0
},
"end_date": "1597968000",
"end_window": {
"hr": 21,
"min": 0,
"ms": 0,
"sec": 0
}
}
}
Full Job Creation Block
This example includes the entire job creation JSON block and all the schedule options.
{
"name":"Simple Scheduled Job",
"kind": "transfer",
"transfer": {
"audit_level": "trace",
"transfer_type": "copy",
"source": {
"connection": { "id": "{{nfs_connection}}" }
,
"target":
{"path":"/sourceFolder"}
},
"destination": {
"connection": { "id": "{{cloud_connection}}" },
"target": {
"path": "/destinationFolder"
}
}
},
"schedule": {
"mode": "auto",
"days": "everyday",
"repeat_count": 0,
"repeat_interval": {
"value": 900000,
"unit": "ms"
},
"end_date": "1523025357",
"end_window": {
"hr": 0,
"min": 0,
"ms": 0,
"sec": 0
},
"max_execution": {
"unit": "d",
"value": 0
},
"run_at": {
"hr": 0,
"min": 0,
"ms": 0,
"sec": 0
},
"start_date": "1523025357",
"start_window": {
"hr": 0,
"min": 0,
"ms": 0,
"sec": 0
}
Convention Job Schedules
The default schedule for a convention job is set to run every 6 hours, allowing it to review the source for any new content. You can edit this schedule as needed using any schedule option preferred. When setting the schedule for convention jobs, you set the schedule for the convention job (the parent job) and the child jobs separately. This allows the child jobs to run on a different schedule than the convention job. You will use the schedule in the transfer block to set the schedule for child jobs and use the schedule outside of the transfer block to set the schedule for the convention job itself.
In the example below,
- The child jobs will use the auto schedule.
- The convention job will use the manual schedule.
{
"name": "Convention job name",
"kind": "personal_drive",
"transfer": {
"transfer_type": "copy",
"source": {
"connection": {
"id": "{{cloud_connection_source}}"
}
},
"destination": {
"connection": {
"id": "{{cloud_connection_destination}}"
}
},
"schedule": {
"mode": "auto"
}
},
"schedule": {
"mode": "manual"
},
"convention": {
"match": "account",
"map_by": {
"email": true
},
"users": "source",
"remove_invalid": true,
"unmapped_policy": "warn",
"type": "personal_drive"
}
}
Clearing Job Settings
Any schedule field can be cleared by setting the value to "null" in a call. For fields that have a default value other than null, removing the value resets the field to its default value.
For example, if days is set to "weekdays," you can clear that setting using the "null" value as in the sample code below. The job will now run every day (the default value).
"schedule": {
"mode": "auto",
"days": "null",
"run_at": {
"hr": 8,
"min": 0,
"sec": 0,
"ms": 0
}
}
Scheduling Multiple Jobs ( Job Queue)
Jobs will run at their next scheduled time, assuming there is an available thread.
The default number of concurrent running jobs is six. This default can be configured by the performance:concurrent_transfers configuration parameter. When all available threads are running jobs, jobs will be queued in the order in which they are triggered. For queued jobs, the Next Run on the Job Detail panel will display a time in the past. A job with a Next Run value of 2 minutes ago will start before a job with a value of 1 minute ago.
Anomalies in the job execution order may occur when jobs are queued and the DryvIQ service is stopped and restarted. In this case, you may see other jobs started before the previously queued jobs.