CronJobs are asynchronous jobs which run periodically. They have the same basic syntax and semantics as AsyncJobs (except they do not have a token attribute), but they also have a Unix CRON compatible control string to specify when they are to run. The full Unix CRON syntax is supported. A small number of CronJobs are set up by default in the system to perform cleanup and maintenance tasks automatically.
The CronJob resource has one public URL. (For information about the difference between Public and Internal URLs and HATEOAS conventions, please see API Structure and Conventions.)
- (String) An optional name for this CronJob.
- (String) An optional description of this CronJob.
- (Boolean) Whether this CronJob is enabled to run or not. Defaults to true.
- (String) When to run this CronJob. The syntax of this string is described below and is in standard CRON format. All standard CRON features are supported.
- (Array) An array of job steps. The syntax and semantics are exactly the same as for AsyncJobs.
- (Integer) The maximum time a job step is assumed to take by default (this can be overridden for each separate job step). Default 30 seconds. If the job should fail for any reason, this is the amount of time it will take before the job is considered again.
- (Integer) The number of job step restarts after which the whole job is to be regarded as poison and removed from the queue (the
creatorwill be notified). Default: 5. The limit can be overridden per job step, and the count is cleared before each step starts.
- (Integer) The maximum number of seconds this CronJob may exist in the queue. Default: 1 day (86400 seconds).
- (String) The username and password (Base64 encoded, cf.
POSTto Authentications) to use in re-authentication. This attribute is required when creating a CronJob, but will never appear in any external resource representation.
- (String) This email address, if present, will receive email notification when an AsyncJob executing this CronJob turns poison. (read only)
- (String) The datetime when this CronJob was created. (read only)
- (String) The datetime when this CronJob was last updated. (read only)
- (String) The datetime when this CronJob was last run. (read only)
The cron attribute must contain a CRON expression string to control when the CronJob is to run. A CRON expression is a string comprising five fields separated by whitespace.
|Field name||Mandatory?||Allowed values||Allowed special characters|
|Day of month||Yes||1-31|| |
|Month||Yes||1-12 or JAN-DEC|| |
|Day of week||Yes||0-6 or SUN-SAT|| |
- Asterisk ( * )
- The asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month.
- Slash ( / )
- Slashes describe increments of ranges. For example 3-59/15 in the 1st field (minutes) indicate the third minute of the hour and every 15 minutes thereafter. The form */... is equivalent to the form "first-last/...", that is, an increment over the largest possible range of the field.
- Comma ( , )
- Commas are used to separate items of a list. For example, using MON,WED,FRI in the 5th field (day of week) means Mondays, Wednesdays and Fridays.
- Hyphen ( - )
- Hyphens define ranges. For example, 2-12 in the fourth field indicates every month between February and December, inclusive.
Predefined scheduling definitions
Several special predefined values can be used as shorthand values for the cron attribute.
||Run once a year at midnight on the morning of January 1|
||Run once a month at midnight on the morning of the first day of the month|
||Run once a week at midnight on Sunday morning|
||Run once a day at midnight|
||Run once an hour at the beginning of the hour|
# * * * * * # ┬ ┬ ┬ ┬ ┬ # │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names) # │ │ │ └────────── month (1 - 12) # │ │ └─────────────── day of month (1 - 31) # │ └──────────────────── hour (0 - 23) # └───────────────────────── min (0 - 59)
The following specifies that the CronJob is to run at one minute past midnight (00:01) of every day of the month, of every day of the week:
1 0 * * *
This example runs the CronJob at 20:00 every day:
0 20 * * *
The following cron value runs the CronJob every two hours, at midnight, 02:00, 04:00, 06:00, 08:00 and so on:
0 */2 * * *
This example runs the CronJob every six minutes during the first 30 minutes of each hour, but only during office hours on Mondays, Wednesdays, and Fridays:
0-29/6 9-17 * * MON,WED,FRI
The following runs the CronJob on midnight on the morning of the first day of every month:
This runs a spooky CronJob at midnight on Friday the 13th:
0 0 13 * FRI
The following hyperlink names are used in the following subsections. To retrieve the URL and
Content-Type to use, use the
_links hash. Note that the URI may change, and thus you should make no inference on how to construct similar URIs from any previous URI. For more information, refer to Hyperlink URIs are Opaque. You may store hyperlink URIs in permanent storage for later use.
The hyperlinks for an CronJob resource are:
- as always, the
selfhyperlink can be used to perform CRUD actions on the AsyncJob resource.
- the ApiUser who created this CronJob.
- the ApiUser who last updated this CronJob.
- the AsyncJob used to handle the last run of this CronJob.
Retrieves a CronJob resource.
- The operation was successful.
Updates a CronJob resource.
PUT requests, according to the RFC standard, require all resource attributes to be updated simultaneously. However, in Ocean
PUT requests have the same semantics as
PATCH requests in that it's possible to set individual attributes. The API will reject requests with missing essential attributes. If you receive unknown properties, you must preserve them and pass them back unchanged in
PATCH requests. Other than that, you should ignore them. This enables the API to be upgraded transparently.
- The operation was successful.
Deletes a CronJob resource.
- The delete operation was successful.
Runs the CronJob resource.
- The operation was successful. No body was returned.
Returns the collection of CronJobs.
- The operation was successful. The collection is returned as a JSON array in the response body.
Creates a new CronJob resource.
- Required attributes:
- Optional attributes:
- The operation was successful and a new CronJob resource has been created. The response headers will, as is customary, include a standard
Locationheader giving the URI of the newly created resource. To save you the extra request Ocean also returns the new CronJob resource in the response body.