In order to run code at fixed intervals in mist-cloud we can use cron jobs. A mist cron job is a mechanism that can be configured to post custom events to the rapids at fixed times. For example, every 5 minutes (*/5 * * * *), or the last weekday of every month (0 0 L * *).
Although the complete syntax of cron expressions is out of the scope of this tutorial, our syntax of cron has 5-6 elements:
Example cron expressions:
*/5 * * * *0 0 L * *0 12 * * 1-50 20 3,23 * *To set up a cron job in mist-cloud simply use the command:
mist cron [name] --expr "[cron expression]" --event [event to post]
Using the 5 minute expression from above it cloud look like this:
mist cron hello --expr "*/5 * * * *"
Meaning, create a cron job called hello, that posts hello every 5 minutes.
⚠ Things to note:
- If event is omitted the name is used.
- A cron event is posted without payload, and replies have no effect.
- Cron jobs are organization wide.
- To prevent accidental updates mist-cli requires you to specify
--overwriteif you want to modify an existing cron job.
You can delete a cron job by specifying an empty expression (""). And finally you can list your current cron jobs with the command:
mist list-crons