我按照 Whenever gems 网站上的说明进行操作,并尝试在服务器上的开发和生产模式下进行操作。
set :output, "/file/to/path/cron.log"
every 1.day, at: '11:59 pm' do
command "sudo touch /file/to/path"
runner "Location.transfer_data",:environment => 'production'
end
它不会创建文件(这是目前的测试,因为我没有生产数据)。
我花了几个小时尝试调试它,crontab -l
给了我这个输出
59 23 * * */bin/bash -l -c 'sudo touch/file/to/path >>/file/to/path/cron.log 2>&1'
59 23 * * */bin/bash -l -c 'cd/var/www/name && script/rails runner -e production '\''Location.transfer_data'\'' >>/file/to/path/cron.log 2>&1'
问候,
巴巴尔拉赫曼
最佳答案
我解决了这个问题,不知 Prop 体是哪一个解决了,但这些是我采取的步骤
- 将作业名称添加到whenever --update-cron 命令
每当 --update-cron jobName
- 重新启动cron 服务
sudo service cron restart
- 授予对日志文件的完全访问权限
sudo chmod 777/path/to/file.log
希望对其他人有用
关于ruby-on-rails - 每当 Gem 和 cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35246112/