Coding Workflow Schedules
As an alternative to defining schedules by using the CLI interface as described in Using a Scheduled Workflow, schedules can be defined in the workflow code as a property in the Object workflow. The properties used in Object workflows are different from the properties used in CLI schedule creation.
The following properties are used in Object workflows:
Table 9-13 Workflow Schedule Properties
Property | Type | Description |
---|---|---|
|
Number |
Determines the starting point in the defined period |
|
Number |
Defines the frequency of the schedule |
|
String |
Specifies if either |
The schedules that are coded into the workflow can be changed by an administrator with appropriate authorizations to the workflow as shown in Using a Scheduled Workflow.
Example 9-16 Using Workflow Properties
The following code example illustrates the use of the properties. Note that inline arithmetic helps to make the offset and period declarations more readable.
// Example of using Schedule definitions within a workflow var MyTextObject = { MyVersion: '1.0', MyName: 'Example 9', MyDescription: 'Example of use of Timer', Origin: 'Oracle' }; var MySchedules = [ // half hr interval { offset: 0, period: 1800, units: "seconds" }, // offset 2 days, 4hr, 30min , week interval {offset: 2*24*60*60+4*60*60+30*60, period: 604800,units: "seconds" } ]; var workflow = { name: MyTextObject.MyName, description: MyTextObject.MyDescription, version: MyTextObject.MyVersion, alert: false, setid: true, schedules: MySchedules, scheduled: true, origin: MyTextObject.Origin, execute: function () { audit('workflow started for timer'); } }
The property units in the Object MySchedules
specifies the type of units used for the properties offset
and period
. They can be set to either seconds
or month
. The property period
specifies the frequency of the event, and the offset
specifies the units within the period. In the previous example, the period in the second schedule is set for a week, starting at the second day, at 4:30 a.m. Multiple schedules can be defined in the property schedules.
The Object MySchedules
in the example uses the following three properties:
-
offset
- This is the starting offset from January 1, 1970 for the schedule. The offset is given in the units defined by the propertyunits
. -
period
- This is the period between recurrences of the schedule, which is also given in the units defined by the propertyunits
. -
units
- This can be defined inseconds
ormonths
.
The starting point for weekly schedules is Thursday. This is because the epoch is defined as starting on 1 Jan 1970, which was a Thursday.
Example 9-17 Workflow Schedule Shown in the CLI
In the previous example, the period in the second schedule uses a starting offset of 2 days + 4 hours + 30 minutes. This results in the starting date being January 3, 1970 at 4:30 a.m. The schedule recurs weekly indefinitely every Saturday at 4:30 a.m. Below, you can see the display of the schedule in the CLI.
hostname:> maintenance workflows hostname:maintenance workflows> list WORKFLOW NAME OWNER SETID ORIGIN VERSION workflow-018 Check metaslab_unload_delay root false Oracle ZFSSA 1.0 workflow-019 Check metaslab_unload_timeout root false Oracle ZFSSA 1.0 workflow-020 Example 9 root true <local> 1.0 workflow-021 Set DNLC size and ncsize root false Data and App 2.0 workflow-022 Stop Existing SSH Sessions root false <local> 0.2 hostname: maintenance workflows> select name="Example 9" hostname: maintenance workflow-020> schedules hostname: maintenance workflow-020 schedules> ls Schedules: NAME FREQUENCY DAY HH:MM schedule-000 halfhour - --:00 schedule-001 week Saturday 04:30