OpenSearch/x-pack/docs/en/watcher/trigger/schedule/cron.asciidoc

71 lines
2.0 KiB
Plaintext

[[schedule-cron]]
==== Cron schedule
Defines a <<trigger-schedule, `schedule`>> using a <<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 * * * ?"
--------------------------------------------------