12

I'm trying to set a Whenever job that should be executed 2 times a day, exactly at 11am and 11pm. Is there any way to do it with only one block? I mean something like this:

every :day, :at => ['11am','11pm'] do
  runner "Task"
end
hippietrail
  • 15,848
  • 18
  • 99
  • 158
Gawyn
  • 1,156
  • 1
  • 10
  • 21

2 Answers2

10

Whenever now supports the syntax proposed in the question.

Just pass an array to the :at option.

every :day, at: ["11am", "11pm"] do
  runner "Task"
end
Ryan McGeary
  • 235,892
  • 13
  • 95
  • 104
8

If you're concerned about DRYness of your code, then how about this?

['11am','11pm'].each do |at|
  every :day, :at => at  do
    runner "Task"
  end  
end
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • 2
    For posterity: this is actually possible as written in the question in the newest version, so this isn't necessary (in case you want to update the answer). – mltsy Mar 11 '14 at 19:29