| 1 |
.. _text_based_def_cron: |
| 2 |
|
| 3 |
cron |
| 4 |
//// |
| 5 |
|
| 6 |
A :term:`cron` defines a time dependency for a :term:`node`, similar to :term:`time`, |
| 7 |
but defined in terms of a time series at which the node is allowed to execute. |
| 8 |
|
| 9 |
.. warning:: |
| 10 |
|
| 11 |
A suite holding a node with a :term:`cron` attribute will **never** reach status *complete*. |
| 12 |
|
| 13 |
A node with a :term:`cron` attribute is immediately set to :term:`queued` after completion. |
| 14 |
In practice, this means that nodes containing a :term:`cron` attribute, and enveloping suites, |
| 15 |
do not reach status *complete*, and their output is not be directly accessible through :term:`ecflow_ui`. |
| 16 |
|
| 17 |
It is **highly discouraged** to create completion :term:`triggers <trigger>` on nodes/suites containing :term:`cron` attributes. |
| 18 |
|
| 19 |
Consider combining the cron attribute together with event and complete attributes to avoid the suite never completing |
| 20 |
-- see more about this usage pattern :ref:`here <cookbook-acquisition_task_pattern>`. |
| 21 |
|
| 22 |
If the task associated with a cron aborts, the :term:`ecflow_server` will not schedule it again. |
| 23 |
|
| 24 |
A :term:`cron` can be parameterised as follows: |
| 25 |
|
| 26 |
.. code-block:: text |
| 27 |
|
| 28 |
cron -w <weekdays> -d <days_of_month> -m <months> <start_time> <end_time> <increment> |
| 29 |
|
| 30 |
Where |
| 31 |
|
| 32 |
- :code:`-w <weekdays>`, defines the days of the week to run the task. |
| 33 |
|
| 34 |
Valid values for :code:`<weekdays>` are: |
| 35 |
|
| 36 |
a) 0 → 6, where 0 is Sunday, 1 is Monday, etc |
| 37 |
b) 0L → 6L, where 0L is last Sunday of the month, 1L is the last Monday, etc |
| 38 |
|
| 39 |
Example: :code:`-w 0,3,6` |
| 40 |
|
| 41 |
It is possible to combine values from a) and b), but without overlaying values. |
| 42 |
In case of overlay, such as :code:`cron -w 0,1,2,1L,2L,3L 23:00` an exception |
| 43 |
will be thrown. |
| 44 |
|
| 45 |
.. warning:: |
| 46 |
|
| 47 |
Support for last weekday of the month is only available in ecFlow 5 or later. |
| 48 |
|
| 49 |
- :code:`-d <days_of_month>`, defines the days of the month to run the task. |
| 50 |
|
| 51 |
Valid values for :code:`<days_of_month>` are in the range [0, 31] or 'L'. |
| 52 |
'L' is used to specify the last day of the month. |
| 53 |
|
| 54 |
Example: :code:`-d 1,2,20,31` |
| 55 |
|
| 56 |
Note: the day of month is ignored if not part of the month, e.g. February 31st. |
| 57 |
|
| 58 |
.. warning:: |
| 59 |
|
| 60 |
Support for last day of the month is only available in ecFlow 5 or later. |
| 61 |
|
| 62 |
- :code:`-m <months>`, defines the months to run the task. |
| 63 |
|
| 64 |
Valid values are in the range [1, 12], where 1 is January, 2 is February, etc. |
| 65 |
|
| 66 |
- :code:`<start_time>`, defines the lower bound time to run the task. |
| 67 |
|
| 68 |
Format :code:`hh:mm` (in 24 hour format). |
| 69 |
|
| 70 |
A :code:`+` prefix can be used to specify a time (maximum of 24 hours) |
| 71 |
relative to suite start time or task requeue time (as part of repeat). |
| 72 |
|
| 73 |
If no :code:`+` prefix is used, the time is interpreted as an absolute wall-clock time. |
| 74 |
|
| 75 |
- :code:`<end_time>`, an optional argument, defines the (inclusive) upper bound time to run the task. |
| 76 |
|
| 77 |
Format :code:`hh:mm` (in 24 hour format). |
| 78 |
|
| 79 |
Necessary when defining multiple steps, must be specified together with <increment>. |
| 80 |
|
| 81 |
Notice that, even though it is never combined with a :code:`+` prefix, the :code:`<end_time>` |
| 82 |
is considered absolute or relative by alignment with the :code:`<start_time>`. |
| 83 |
|
| 84 |
- :code:`<increment>`, an optional argument, defines the time duration between task runs. |
| 85 |
|
| 86 |
Format :code:`hh:mm` (in 24 hour format). |
| 87 |
|
| 88 |
Necessary when defining multiple steps, must be specified together with <end_time>. |
| 89 |
|
| 90 |
|
| 91 |
Here are some examples of :term:`cron` usage: |
| 92 |
|
| 93 |
.. code-block:: shell |
| 94 |
|
| 95 |
cron 11:00 |
| 96 |
# Run every day, at 11am |
| 97 |
# Python: cron = Cron("11:00") |
| 98 |
|
| 99 |
cron 10:00 22:00 00:30 |
| 100 |
# Run every day, every 30 minutes, from 10:00 until (and including) 22:00 |
| 101 |
# Python: cron = Cron("10:00 22:00 00:30") |
| 102 |
|
| 103 |
cron +00:20 23:59 00:30 |
| 104 |
# Considering <start_time> the suite start time or task requeue time |
| 105 |
# run at <start_time>+20 minutes, and then every 30 minutes until (and including) <start_time>+23:59. |
| 106 |
# After this the cron will not run again, unless reset. |
| 107 |
# Python: cron = Cron("+00:20 23:59 00:30") |
| 108 |
|
| 109 |
cron -w 0,1 10:00 11:00 01:00 |
| 110 |
# Run every Sunday(0) & Monday(1), at 10am and 11am |
| 111 |
# Python: cron = Cron("10:00 11:00 01:00", days_of_week=[0, 1]) |
| 112 |
|
| 113 |
cron -d 15,16 -m 1 10:00 11:00 01:00 |
| 114 |
# Run January 15th and 16th, at 10am and 11am |
| 115 |
# Python: cron = Cron("10:00 11:00 01:00", days_of_month=[15, 16]) |
| 116 |
|
| 117 |
cron -w 5L 23:00 |
| 118 |
# Run on *last* Friday(5L) of each month, at 11pm |
| 119 |
# Python: cron = Cron("23:00",last_week_days_of_the_month=[5]) |
| 120 |
|
| 121 |
cron -w 0,1L 23:00 |
| 122 |
# Run every Sunday(0) and *last* Monday(1L) of the month, at 11pm |
| 123 |
# Python: cron = Cron("23:00", days_of_week=[0], last_week_days_of_the_month=[1]) |
| 124 |
|
| 125 |
cron -w 0L,1L,2L,3L,4L,5L,6L 10:00 |
| 126 |
# Run on the last Monday(1), Tuesday(2), ..., Sunday(0) of the month, at 10am |
| 127 |
# Python: cron = Cron("10:00", last_week_days_of_the_month=[0, 1, 2, 3, 4, 5, 6]) |
| 128 |
|
| 129 |
cron -d 1,L 23:00 |
| 130 |
# Run on the first and last of the month, at 11pm |
| 131 |
# Python: cron = Cron("23:00", days_of_week=[1], last_day_of_the_month=True) |
| 132 |
|
| 133 |
|
| 134 |
If the time the job takes to complete is longer than the interval a “slot” is missed, |
| 135 |
e.g.: |
| 136 |
|
| 137 |
.. code-block:: shell |
| 138 |
|
| 139 |
cron 10:00 20:00 01:00 |
| 140 |
|
| 141 |
if the 10:00 run takes more than an hour, the 11:00 run will never occur. |
| 142 |
|
| 143 |
Absolute vs relative time series |
| 144 |
------------------------------------- |
| 145 |
|
| 146 |
The :code:`<start_time>` (and, when present, :code:`<end_time>`) of a :term:`cron` can be given |
| 147 |
as an **absolute** wall-clock time (:code:`hh:mm`), or as a time **relative** to the |
| 148 |
suite start time or the last :term:`repeat` increment, using the :code:`+` prefix |
| 149 |
(:code:`+hh:mm`). The two forms repeat very differently once a day boundary is crossed. |
| 150 |
|
| 151 |
Absolute time series |
| 152 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 153 |
|
| 154 |
An absolute time series automatically restarts itself every day at midnight: as soon as the |
| 155 |
day changes, the series rewinds back to :code:`<start_time>` and starts matching wall-clock time |
| 156 |
slots again. No extra attribute is required for this — it happens on its own, indefinitely. |
| 157 |
|
| 158 |
For example, given :code:`cron 00:00 23:00 01:00` on a suite that begins at 22:01: |
| 159 |
|
| 160 |
.. list-table:: |
| 161 |
:header-rows: 1 |
| 162 |
|
| 163 |
* - Day |
| 164 |
- Wall-clock times the node is freed |
| 165 |
* - Day 1 (suite begins 22:01) |
| 166 |
- 23:00 only — earlier slots (00:00-22:00) had already passed by the time the suite began |
| 167 |
* - Day 2 |
| 168 |
- 00:00, 01:00, 02:00, ..., 23:00 (24 times) |
| 169 |
* - Day 3 onward |
| 170 |
- Same as Day 2 — repeats indefinitely, automatically |
| 171 |
|
| 172 |
Relative (+) time series |
| 173 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 174 |
|
| 175 |
A relative time series has no such automatic reset. Its elapsed countdown starts at the suite |
| 176 |
begin time (or the last :term:`repeat` increment/re-queue) and keeps counting up; it does **not** |
| 177 |
rewind at midnight. Once the elapsed time exceeds :code:`<end_time>`, the cron stops becoming |
| 178 |
free and will never become free again on its own. |
| 179 |
|
| 180 |
For example, given :code:`cron +00:00 23:00 01:00` on a suite that begins at 22:01: |
| 181 |
|
| 182 |
.. list-table:: |
| 183 |
:header-rows: 1 |
| 184 |
|
| 185 |
* - Elapsed since suite begin |
| 186 |
- Wall-clock |
| 187 |
- Node freed? |
| 188 |
* - +00:00 |
| 189 |
- 22:01 (day 1) |
| 190 |
- Yes — immediately, since elapsed time is already at the start slot |
| 191 |
* - +01:00 |
| 192 |
- 23:01 (day 1) |
| 193 |
- Yes |
| 194 |
* - +02:00, +03:00, ..., +22:00 |
| 195 |
- 00:01, 01:01, ..., 20:01 (day 2) |
| 196 |
- Yes — every hour, regardless of the day change; only the elapsed time matters |
| 197 |
* - +23:00 |
| 198 |
- 21:01 (day 2) |
| 199 |
- Yes — last valid slot, since elapsed time has reached the :code:`<end_time>` bound |
| 200 |
* - +24:00 (the next slot would be) |
| 201 |
- 22:01 (day 2) |
| 202 |
- No — exceeds the 23-hour :code:`<end_time>` bound; the cron is now permanently inactive |
| 203 |
|
| 204 |
.. note:: |
| 205 |
|
| 206 |
To keep a relative :term:`cron` running indefinitely across days, it must be paired with a |
| 207 |
:term:`repeat` attribute. |
| 208 |
|
| 209 |
|
| 210 |
Keeping a relative cron alive across days |
| 211 |
----------------------------------------- |
| 212 |
|
| 213 |
A **relative** :term:`cron` (one whose :code:`<start_time>` uses the :code:`+` prefix, see |
| 214 |
:ref:`text_based_def_cron`) is anchored once, at suite begin time, and its elapsed countdown |
| 215 |
never rewinds at midnight. Once the elapsed time runs past :code:`<end_time>`, the cron stops |
| 216 |
becoming free and stays inactive forever — unless something resets it. |
| 217 |
|
| 218 |
The way to reset a :term:`cron`, and so keep a relative cron running indefinitely day after day, is to |
| 219 |
pair it with a :term:`repeat` attribute placed on the **same** node as the cron, with a plain |
| 220 |
dummy :term:`task` underneath (a task with no time attributes of its own). Each time the repeat |
| 221 |
increments, the relative cron's elapsed window is reset. |
| 222 |
|
| 223 |
.. code-block:: shell |
| 224 |
|
| 225 |
family example |
| 226 |
repeat day 1 |
| 227 |
cron +00:00 23:00 01:00 |
| 228 |
task dummy |
| 229 |
endfamily |
| 230 |
|
| 231 |
The cron must **not** be placed directly on the dummy task instead of the family: a node with a |
| 232 |
cron attribute is immediately requeued as soon as it completes, so it never reports completion |
| 233 |
up to a parent's :term:`repeat` — thus, the :term:`repeat` would then never advance. |