Ruby on rails Cron作业没有';t运行';跑步者';使用Sidekiq的任务
我使用gem生成了一个Cront作业Ruby on rails Cron作业没有';t运行';跑步者';使用Sidekiq的任务,ruby-on-rails,ruby,cron,sidekiq,whenever,Ruby On Rails,Ruby,Cron,Sidekiq,Whenever,我使用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/ww
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'\'''
显然,命令
任务工作正常,我每隔15分钟将日期
打印到cron.txt
,但是运行程序
任务没有运行
Location.update\u days
调用Sidekiq worker来执行任务,它在从rails控制台运行时工作,但在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脚本来查看是否有明显的错误吗?在Ruby类加载之前,cron作业可能会失败
/bin/bash -l -c 'cd /opt/www/my_app && bin/rails runner -e production '\''Location.update_days'\'''
是的,它会提示我到新行,在行的开头显示一个
,就像在rails控制台中一样,但是如果我键入类似Location.first的内容并按enter键,只会提示我转到另一个新行,而不显示任何结果。你认为这是为什么?显然是反斜杠造成的问题。如果没有它们,它可以在控制台中工作,但这有点奇怪,因为它们是由$bin/rails runner-e production'Location.update_days'