【问题标题】:Whenever gem in rails is not running每当 Rails 中的 gem 没有运行时
【发布时间】:2016-04-11 05:45:46
【问题描述】:

我有一个用于向系统中的用户发送电子邮件的 cron 作业,但它不想运行。我在日志中收到以下错误消息:

rake aborted!
Don't know how to build task 'cron:deliver_email'
/Users/ghost/.rvm/gems/ruby-2.2.1@maalify/bin/ruby_executable_hooks:15:in `eval'
/Users/ghost/.rvm/gems/ruby-2.2.1@maalify/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)

我的 schedule.rb 是这样的

set :environment, "development"
set :whenever_command, "bundle exec whenever"
set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"}


every 1.minute do
  command "gem install rake"
  rake 'cron:deliver_email'
end

如果我使用 rake cron:deliver_email 从命令行执行,则所述 rake 任务 (rake 'cron:deliver_email') 运行正常

我已经在我的 Gemfile 中添加了 not require 语句 (:require => false)。

这就是我的 cron 工作的样子

▶ whenever 
* * * * * /bin/bash -l -c 'gem install rake >> log/cron_log.log 2>> log/cron_error_log.log'

* * * * * /bin/bash -l -c 'cd /Users/ghost/code/IdeaProjects/maalify && RAILS_ENV=development bundle exec rake cron:deliver_email --silent >> log/cron_log.log 2>> log/cron_error_log.log'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

【问题讨论】:

    标签: ruby-on-rails ruby bash cron whenever


    【解决方案1】:

    你需要告诉 cron 加载 rvm 环境。在此处查看详细信息:

    https://rvm.io/deployment/cron

    【讨论】:

    • 生产环境中的 rbenv 怎么样。因为我在生产中使用 rbenv。
    • 您发布的错误输出表明正在使用rvm。您应该尽量不要在您的环境之间使用不同的工具。无论如何,对于rbenv,请参阅此答案:stackoverflow.com/questions/8434922/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多