我使用任何时候的gem生成了一个Cront作业
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 worker来执行任务,当从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你知道可能是哪里出了问题吗?或者我该如何调试这个问题?
发布于 2015-09-11 03:48:34
我知道您说它可以从控制台运行,但是您有没有尝试运行cron作业运行的bash脚本来查看是否有明显的错误?甚至在加载Ruby类之前,cron作业就有可能失败。
/bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''https://stackoverflow.com/questions/32509930
复制相似问题