Rails - Whenever gem - Dynamic values

后端 未结 4 1803
Happy的楠姐
Happy的楠姐 2020-12-05 21:08

Lets say I have a cronjob like this:

every 1.day, :at => \'4:30 am\' do  
  runner \"MyModel.task_to_run_at_four_thirty_in_the_morning\"  
end  
         


        
4条回答
  •  悲&欢浪女
    2020-12-05 21:43

    # In rails 4
    require File.expand_path('../..//config/environment.rb', __FILE__)
    
    # This is your table by which you will get your new value 
    bid_update = DynamicOfferTime.first
    
    # Now Task As
    every (bid_update.hour_value).hours do
      puts "This will repeat in every #{bid_update.hour_value} hour"
    end
    

    Do not forget to update whenever

提交回复
热议问题