How to use every time gem starts a task at 2 a.m. and 2 p.m.?

I am currently running 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 only one cron declaration for both cases?

+5
source share
1 answer

According to the test in each repository you can pass an 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 your case, it should be fine, as

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

Source: https://habr.com/ru/post/1245169/


All Articles