gpt4 book ai didi

ruby-on-rails - bundle exec rake 不在 cron 中运行

转载 作者:数据小太阳 更新时间:2023-10-29 08:32:02 24 4
gpt4 key购买 nike

我做了一些研究,但所有与 cron 和 bundle exec 相关的内容都没有涵盖我遇到的问题,如果已经讨论过,请再次打扰。

我正在运行 Ubuntu 13.10 并有一个 Ruby On Rails 应用程序,其中几乎没有每隔几分钟左右就需要在 Cron 上运行的 rake 任务。

我在 whenever gem 的帮助下运行了这个语法

every 3.minutes do
rake 'update_balance'
end

转换到 crontab 文件中的这一行

0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'

当我完全复制这一行时

/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'

并在它的控制台中运行,它运行得非常好,并按预期更新了数据库中的几条记录。

但是当设置为 cron 时,我可以看到它在/var/log/syslog 文件中运行,但没有真正执行。

May 13 13:06:01 sandbox2 CRON[9656]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')
May 13 13:06:01 sandbox2 CRON[9655]: (CRON) info (No MTA installed, discarding output)
May 13 13:09:01 sandbox2 CRON[9789]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')

即使我将 &>/tmp/mycommand.log 添加到 crontab 命令,每次下一次启动 cron 命令都会完全截断此文件,但是,如果我手动启动它,它会很好地工作并给我留下这个输出。

2014-05-13T11:11:25Z 10292 TID-2asbo INFO: Sidekiq client with redis options  {:url=>"redis://127.0.0.1"}
Sent task for updating 2 users

非常感谢您对此问题的任何帮助。谢谢。

最佳答案

我以前遇到过这样的问题,因为 cron 是以不同的用户身份运行的。特别是对于 rake,我必须使用 rake 的完整路径,因为 cron 用户的 PATH 中没有正确的文件夹。

因此,我的 rake 任务 cron 行如下所示:

30 8 * * 1 cd /ebs/www/apps/myproject/www && /usr/local/bin/rake mailer:send_weekly_expiring_users_reminder RAILS_ENV=production

关于ruby-on-rails - bundle exec rake 不在 cron 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23634750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com