Skip to content

Commit 9324f64

Browse files
authored
Add cron character explanation and give examples of different schedules
Signed-off-by: tpmccallum [email protected] Signed-off-by: Timothy McCallum <[email protected]>
1 parent 28b14ed commit 9324f64

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,45 @@ spin build --up
4848

4949
## Trigger Configuration
5050

51-
The trigger type is `cron` and there are no application-level configuration options.
51+
The trigger type is `cron`, and there are no application-level configuration options.
5252

5353
The following options are available to set in the [[trigger.cron]] section:
5454

5555
| Name | Type | Required? | Description |
5656
|-----------------------|------------------|-----------|-------------|
5757
| `component` | string or table | required | The component to run on the schedule given in `cron_expression`. (This is the standard Spin trigger component field.) |
58-
| `cron_expression` | string | required | The `cron` expresison describing the schedule on which to execute the component. |
58+
| `cron_expression` | string | required | The `cron` expression describes the schedule for executing the component. |
59+
60+
### Cron Expression Fields
61+
62+
The `cron_expression` format for scheduling is as follows:
63+
64+
```text
65+
sec min hour day of month month day of week year
66+
* * * * * * *
67+
```
68+
69+
### Cron Expression Characters
70+
71+
The `*` indicates that every value applies; i.e., if `sec` is set to `*`, then every second will trigger execution.
72+
The `/` indicates increments. For example, if `sec` is set to `0/15`, then starting at `0`, the trigger will be executed every 15 seconds.
73+
The `,` separates values. For example, if `sec` is set to `2,8`, then the trigger will execute only on the 2nd and 8th seconds of every minute.
74+
The `-` indicates range, i.e., if the `sec` is set to `5-10`, then the trigger will execute only on the 5th, 6th, 7th, 8th, 9th, and 10th seconds of each minute.
75+
The `0` indicates no execution. If the `sec` is set to `0`, then the trigger can only execute on higher field values such as `min`, `hour`, etc. The lowest second increment is 60 (one minute)
76+
77+
Here is one example that combines a few of the fields mentioned above:
78+
79+
```text
80+
sec min hour day of month month day of week year
81+
0 1/2 11,12 5-10 * * *
82+
```
83+
84+
The above schedule of `0 1/2 11,12 5-10 * * *` will execute on the first minute and every subsequent 2 minutes during the 11th hour and the 12 hour (noon) on days 5 through 10 of every month (regardless of the day of the week) and this will repeat through every year.
5985

6086
## Building Cron Components
6187

6288
Currently only a Rust SDK is supported for guest components. The `spin-cron-sdk` along with the [`spin_sdk` crate](https://docs.rs/spin-sdk) can be used to build cron components. The guest code must have a function decorated with the `#[cron_component]` macro. See `guest/src/lib.rs` for an example in rust.
6389

6490
The signature of the function must be `fn handle_cron_event(metadata: Metadata) -> Result<(), Error>`.
6591

66-
The `Metadata` object contains a single field `timestamp` which contains the duration since 00:00:00 UTC on 1 January 1970 (the Unix epoch) in seconds.
92+
The `Metadata` object contains a single field `timestamp` which contains the duration since 00:00:00 UTC on 1 January 1970 (the Unix epoch) in seconds.

0 commit comments

Comments
 (0)