Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use whenever gem to run a task at 2 am AND 2 pm?

Currently I run this code:

every 1.day, at: '2am' do
  rake 'data:load_direct_monitoring_statistics'
end if @environment == 'production'
every 1.day, at: '2pm' do
  rake 'data:load_direct_monitoring_statistics'
end if @environment == 'production'

This code works as intended, but: is there a way to use just one cron declaration to cover both cases?

like image 215
Luis Masuelli Avatar asked Oct 18 '22 13:10

Luis Masuelli


1 Answers

According to test in whenever repository you should be able to pass Array

every "weekday", :at => %w(5:02am 3:52pm) do

Here is the source> https://github.com/javan/whenever/blob/334cfa01f373006cc032e23907b1777a8ea3f3b0/test/functional/output_at_test.rb

So in you case it should be ok to do like

every 1.day, at: ['2am','2pm'] do
  rake 'data:load_direct_monitoring_statistics'
end if @environment == 'production'
like image 70
Ragnarokk Avatar answered Oct 24 '22 12:10

Ragnarokk