A schedule is defined by a string using the cron syntax. This syntax is extremely flexible and powerful, but can be hard to understand. The fields are as follows:
- Seconds (0-59)
- Minutes (0-59)
- Hours (0-23)
- Day-of-Month (1-31)
- Month (1-12) OR jan,feb,mar, apr ...
- Day-of-Week (0-7) (Sunday is 0 or 7) OR sun, mon, tue, wed, thu, fri, sat
- Year (optional field)
"0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm"
"0 0/5 * * * ?" - means Fire every 5 minutes
"0 0 2 * * ?" - means Fire at 2am every day
Note: Rule Timer schedules are in GMT/UTC.
Associated Expression Rules
The Rule timer has no other purpose but to run Expression Rules. These rules can be System or Asset. SystemTimer means an Expression Rule with type set to SystemTimer. This rule will be run once per scheduled time. A system timer can run a script to export data every day, or enable some rules at the end of a beta program.
The other type is an Expression Rule with type AssetTimer. This rule will be run for all associated assets at the scheduled time. Say you want to save the max speed every day for a fleet of vehicles. You have an Expression Rule that's associated with the model Vehicle. The rule A Rule Timer is set to run every day.
If: Speed > MaxSpeed
Then: SetDataItem("MaxSpeed", Speed)
If MaxSpeed > 0
Then: SetDataItem("DailyMax", MaxSpeed) && SetDataItem("MaxSpeed", 0)
Associated to Vehicles
Schedule "0 0 9 * * * ?"
Associated rule: DailyMax
The SetMax rule stores the max speed in a dataitem for each Vehicle asset. The NightlyUpdate timer runs at 9am UTC (which is 3am Eastern US, and midnight PST.) It writes the max into a DailyMax dataitem and clears the MaxSpeed to get ready for another day. The effect of the timer is that each Vehicle asset will process an event and run any rules that apply to it.
Note! If you create the MaxSpeed dataitem through the model wizard, it doesn't have an initial value! So the rule IF Speed > MaxSpeed will not do the comparison until the first day when the timer sets its value to be 0.