[英]Cron job doesn't run 'runner' task that uses Sidekiq
我使用Whenever gem生成了Cront Job
every 15.minutes do
command "date >> ~/cron.txt"
runner "Location.update_days"
end
通過在命令行中輸入crontab -l
,我得到:
0,15,30,45 * * * * /bin/bash -l -c 'date >> ~/cron.txt'
0,15,30,45 * * * * /bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''
顯然, command
任務可以正常工作,我確實每15分鍾將date
打印到cron.txt
但runner
任務無法運行。
Location.update_days
調用Sidekiq工作者來執行任務,並且它在從rails console
運行時有效,但在cron調用時則不起作用。
def self.update_days
new_day = self.new_day
self.where( current_location: true,
self.season => new_day[:timezone]
).find_each do |location|
day = location.days.create new_day
SidekiqWorker.perform_async day.id
end
end
您是否知道可能出什么問題或如何調試該問題?
我知道您說它是從控制台正常運行的,但是您是否嘗試運行cron作業運行的bash腳本,以查看是否存在明顯的錯誤? cron作業有可能在Ruby類加載之前就失敗了。
/bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.