如何在 schedule.rb 文件中传递动态值( Ruby on rails )
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 它更好,因为现在你想做的是在调度程序文件上放置一些逻辑,这可能会在以后咬你
如何在正则表达式中传递动态值
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 它更好,因为现在你想做的是在调度程序文件上放置一些逻辑,这可能会在以后咬你