[英]How do i access constant defined in Rails 3 application in “whenever” gem of schedule.rb file
[英]How to pass dynamic value in schedule.rb file ( Ruby on rails )
如何在正则表达式中传递动态值
new_date_value = query_value
# minute(0-59), hours(0-23), day of month(1-31), month of year(1-12), day of week(0-6) 0=sunday
every '0 4 #{new_date_value} * *' do
rake "db:get_free_tag_latest_post_batch", :environment => "production"
end
为了避免这种事情,我通常会检查任务上的日期。 例如,我有一个任务必须在每个月的最后一天运行。 例如,我不能在当天使用30
或31
,因为 2 月有 28 天。
这就是我设置任务的方式
# Apply interest accrued for all loans
# every day at: '22:00'
trigger_interest_accrued_application:
cron: "0 22 * * *"
class: "Jobs::TriggerInterestAccruedApplication"
queue: admin
以及关于任务定义
class TriggerInterestAccruedApplication < ::ApplicationJob
queue_as :admin
def perform
return unless Date.current.end_of_month.today?
perform_task
end
end
你认为这样的事情对你有用吗? IMO 更好,因为现在您要做的是在调度程序文件中添加一些逻辑,这可能会在以后咬您
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.