elasticsearch/docs/reference/watcher/trigger/schedule/cron.asciidoc
Luke Whiting 1d4c8d85f6
(#34659) - Add Timezone Configuration to Watcher (#117033)
* Add timezone support to Cron objects

* Add timezone support to CronnableSchedule

* XContent change to support parsing and display of TimeZone fields on schedules

* Case insensitive timezone parsing

* Doc changes

* YAML REST tests

* Equals, toString and HashCode now include timezone

* Additional random testing for DST transitions

* Migrate Cron class to use wrapped LocalDateTime

The algorithm depends on some quirks of calendar but LocalDateTime
correctly ignores DST during calculations so this uses a LocalDateTime
with a wrapper to emulate some of Calendar's behaviours that the Cron
algorithm depends on

* Additional documentation to explain discontinuity event behaviour

* Remove redundant conversions from ZoneId to TimeZone following move to LocalDateTime

* Add documentation warning that manual clock changes will cause unpredictable watch execution

* Update docs/reference/watcher/trigger/schedule.asciidoc

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>

---------

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>
2024-11-25 09:51:11 +00:00

99 lines
2.7 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
[[configue_cron_time-zone]]
==== Use a different time zone for a cron schedule
By default, cron expressions are evaluated in the UTC time zone. To use a different time zone,
you can specify the `timezone` parameter in the schedule. For example, the following
`cron` schedule triggers at 6:00 AM and 6:00 PM during weekends in the `America/Los_Angeles` time zone:
[source,js]
--------------------------------------------------
{
...
"trigger" : {
"schedule" : {
"timezone" : "America/Los_Angeles",
"cron" : [
"0 6,18 * * * 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 * * * ?"
--------------------------------------------------