«
Rule languages supports cron features
rule 'Log the rule name every second' do | rule |
  every :second
  run { logger.info "Rule '#{rule.name}' executed" }
enddef five_seconds_from_now_string
  (Time.now + 5).strftime('%H:%M:%S')
end
def five_seconds_from_now_tod
  TimeOfDay.parse(five_seconds_from_now_string)
end
rule 'Simple' do | rule |
  every  <%= ":#{Date.today.strftime('%A').downcase.to_sym}" %>, at: <five_seconds_from_now>
  run { logger.info "Rule #{rule.name} executed" }
end| five_seconds_from_now | |
|---|---|
| five_seconds_from_now_string | |
| five_seconds_from_now_tod | 
rule 'Every 5 seconds' do | rule |
  every 5.seconds
  run { logger.info "Rule #{rule.name} executed" }
endtime = (Time.now + 3).strftime('%H:%M:%S')
today = ZonedDateTime.now
def monthday(zdt)
  MonthDay.of(zdt.month_value, zdt.day_of_month)
end
rule 'Every MonthDay' do
  every <monthday>, at: time
  run { logger.info "Rule Every MonthDay executed" }
end| monthday | should | |
|---|---|---|
| monthday(today) | should | |
| monthday(today).to_s | should | |
| monthday(today.plus_days(1)) | should not | |
| monthday(today.minus_days(1)) | should not | |
| monthday(today.plus_months(1)) | should not | |
| monthday(today.minus_months(1)) | should not |