0

我正在尝试将每当 gem添加到我的 Rails 项目中,我将 gem 添加到 Gemfile

gem "whenever", "~> 0.8.4"

并且安装没有任何问题。然后我在生成的schedule.rb文件中添加了一个简单的任务:

 set :output, "/home/my_deploy_name/project_name/current/log/cron_log.log"

 every 2.minutes do
   command "/usr/bin/some_great_command"
   runner "MyModel.some_method"
   rake "some:great:rake:task"
   puts "It's working !!!"
 end

然后我在文件中添加了以下内容deploy.rb

set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
namespace :deploy do
  desc "Update the crontab file"
  task :update_crontab, :roles => :db do
    run "cd #{latest_release} && whenever --update-crontab #{application}"
  end
end

我尝试设置latest_release,current_pathrelease_path,但在所有情况下总是相同的输出:

*** [err :: IP] sh: 1:
*** [err :: IP] whenever: not found
*** [err :: IP]
...
*** [err :: 54.221.241.111] /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem'
*** [err :: IP] :
*** [err :: IP] whenever is not part of the bundle. Add it to Gemfile.
*** [err :: IP] (
*** [err :: IP] Gem::LoadError
*** [err :: IP] )
*** [err :: IP] from /home/my_deploy_name/project_name/shared/bundle/ruby/2.0.0/bin/whenever:22:in `<main>'

如何解决这个问题?(我正在部署到 Amazon EC2 - ubuntu)

谢谢

4

1 回答 1

1

“每当”我遇到了这个问题......

只是在开玩笑。实际上,这与 capistrano 有关,而不是任何时候。您在没有包上下文的情况下调用 deploy.rb 中的when命令。

run "cd #{latest_release} && whenever --update-crontab #{application}"

尝试这个:

run "cd #{latest_release} && bundle exec whenever --update-crontab #{application}"
于 2013-11-27T08:24:34.507 回答