Duration
Ruby integers and floats are extended with several methods to support durations. These methods create a new java.time.Duration object that is used by the Every trigger, delay, the for option and timers.
Extended Methods
Method | Description | Examples |
---|---|---|
hour or hours | Convert number to hours | 1.hour , 2.5 hours |
minute or minutes | Convert number to minutes | 3.minutes |
second or seconds | Convert number to seconds | 5.seconds |
millis or millisecond or milliseconds or ms | Convert number to milliseconds | 200.ms |
Examples
rule 'run every 30 seconds' do
every 30.seconds
run { logger.info('Hello') }
end
rule 'Warn about open door' do
changed FrontDoor, to: OPEN, for: 10.minutes
run { |event| logger.info("#{event.item.name} has been open for 10 minutes") }
end
rule 'Timer example' do
on_start
run do
after(3.hours) { logger.info('3 hours have passed') }
end
end