elasticsearch/docs/reference/watcher/trigger/schedule/cron.asciidoc
James Rodewig 255c9a7f95
[DOCS] Move x-pack docs to docs/reference dir (#99209)
**Problem:**
For historical reasons, source files for the Elasticsearch Guide's security, watcher, and Logstash API docs are housed in the `x-pack/docs` directory. This can confuse new contributors who expect Elasticsearch Guide docs to be located in `docs/reference`. 

**Solution:**
- Move the security, watcher, and Logstash API doc source files to the `docs/reference` directory
- Update doc snippet tests to use security

Rel: https://github.com/elastic/platform-docs-team/issues/208
2023-09-12 14:53:41 -04:00

75 lines
2 KiB
Text

[[schedule-cron]]
==== {watcher} cron schedule
++++
<titleabbrev>Cron schedule</titleabbrev>
++++
Defines a <<trigger-schedule, `schedule`>> using a <<api-cron-expressions, cron expression>>
that specifiues when to execute a watch.
TIP: While cron expressions are powerful, a regularly occurring schedule
is easier to configure with the other schedule types.
If you must use a cron schedule, make sure you verify it with
<<elasticsearch-croneval, `elasticsearch-croneval`>> .
===== Configure a cron schedule with one time
To configure a `cron` schedule, you simply specify the cron expression as a
string value. For example, the following snippet configures a `cron` schedule
that triggers every day at noon:
[source,js]
--------------------------------------------------
{
...
"trigger" : {
"schedule" : {
"cron" : "0 0 12 * * ?"
}
}
...
}
--------------------------------------------------
// NOTCONSOLE
[[_configuring_a_multiple_times_cron_schedule]]
===== Configure a cron schedule with multiple times
To configure a `cron` schedule that triggers multiple times, you can
specify an array of cron expressions. For example, the following `cron`
schedule triggers every even minute during weekdays and every uneven
minute during the weekend:
[source,js]
--------------------------------------------------
{
...
"trigger" : {
"schedule" : {
"cron" : [
"0 0/2 * ? * MON-FRI",
"0 1-59/2 * ? * SAT-SUN"
]
}
}
...
}
--------------------------------------------------
// NOTCONSOLE
[[croneval]]
===== Use croneval to validate cron expressions
{es} provides a <<elasticsearch-croneval, `elasticsearch-croneval`>> command line tool
in the `$ES_HOME/bin` directory that you can use to check that your cron expressions
are valid and produce the expected results.
To validate a cron expression, pass it in as a parameter to `elasticsearch-croneval`:
[source,bash]
--------------------------------------------------
bin/elasticsearch-croneval "0 0/1 * * * ?"
--------------------------------------------------