2016-10-28 00:36:26 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "periodic Stanza - Job Specification"
|
|
|
|
sidebar_current: "docs-job-specification-periodic"
|
|
|
|
description: |-
|
|
|
|
The "periodic" stanza allows a job to run at fixed times, dates, or intervals.
|
|
|
|
The easiest way to think about the periodic scheduler is "Nomad cron" or
|
|
|
|
"distributed cron".
|
|
|
|
---
|
|
|
|
|
|
|
|
# `periodic` Stanza
|
|
|
|
|
|
|
|
<table class="table table-bordered table-striped">
|
|
|
|
<tr>
|
|
|
|
<th width="120">Placement</th>
|
|
|
|
<td>
|
|
|
|
<code>job -> **periodic**</code>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
The `periodic` stanza allows a job to run at fixed times, dates, or intervals.
|
|
|
|
The easiest way to think about the periodic scheduler is "Nomad cron" or
|
|
|
|
"distributed cron".
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "docs" {
|
|
|
|
periodic {
|
|
|
|
cron = "*/15 * * * * *"
|
|
|
|
prohibit_overlap = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-03-15 18:29:36 +00:00
|
|
|
The periodic expression by default evaluates in the **UTC timezone** to ensure
|
2016-10-28 00:36:26 +00:00
|
|
|
consistent evaluation when Nomad spans multiple time zones.
|
|
|
|
|
2017-01-26 03:14:58 +00:00
|
|
|
## `periodic` Requirements
|
|
|
|
|
|
|
|
- The job's [scheduler type][batch-type] must be `batch`.
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
## `periodic` Parameters
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `cron` `(string: <required>)` - Specifies a cron expression configuring the
|
2016-10-28 00:36:26 +00:00
|
|
|
interval to launch the job. In addition to [cron-specific formats][cron], this
|
|
|
|
option also includes predefined expressions such as `@daily` or `@weekly`.
|
|
|
|
|
|
|
|
- `prohibit_overlap` `(bool: false)` - Specifies if this job should wait until
|
|
|
|
previous instances of this job have completed. This only applies to this job;
|
|
|
|
it does not prevent other periodic jobs from running at the same time.
|
|
|
|
|
2017-02-15 22:37:06 +00:00
|
|
|
- `time_zone` `(string: "UTC")` - Specifies the time zone to evaluate the next
|
|
|
|
launch interval against. This is useful when wanting to account for day light
|
|
|
|
savings in various time zones. The time zone must be parsable by Golang's
|
|
|
|
[LoadLocation](https://golang.org/pkg/time/#LoadLocation).
|
|
|
|
|
2016-10-28 00:36:26 +00:00
|
|
|
## `periodic` Examples
|
|
|
|
|
|
|
|
The following examples only show the `periodic` stanzas. Remember that the
|
2016-10-31 00:41:03 +00:00
|
|
|
`periodic` stanza is only valid in the placements listed above.
|
2016-10-28 00:36:26 +00:00
|
|
|
|
|
|
|
### Run Daily
|
|
|
|
|
|
|
|
This example shows running a periodic job daily:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
periodic {
|
|
|
|
cron = "@daily"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-03-15 18:29:36 +00:00
|
|
|
### Set Time Zone
|
|
|
|
|
|
|
|
This example shows setting a time zone for the periodic job to evaluate in:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
periodic {
|
|
|
|
cron = "*/15 * * * * *"
|
|
|
|
time_zone = "America/New_York"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-26 03:14:58 +00:00
|
|
|
[batch-type]: /docs/job-specification/job.html#type "Batch scheduler type"
|
2016-10-28 00:36:26 +00:00
|
|
|
[cron]: https://github.com/gorhill/cronexpr#implementation "List of cron expressions"
|