Cron 作业使用 Whenever gem 而不是 运行 正确
Cron job using Whenever gem not running properly
我使用 whenever
gem 编写了一个 cron 作业。这是我的 schedule.rb
env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']
set :output, "log/cron_log.log"
every 2.minutes do
runner "Action.cron_actions_ranking" , :environment => 'development'
end
因此,每隔 2 分钟我的 cron_log 文件就会填充以下持续性错误:
/home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find minitest-5.8.3 in any of the sources (Bundler::GemNotFound)
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:85:in `map!'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:85:in `materialize'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:132:in `specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:177:in `specs_for'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:166:in `requested_specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/environment.rb:18:in `requested_specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/runtime.rb:13:in `setup'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler.rb:122:in `setup'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/setup.rb:18:in `<top (required)>'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /home/haseeb/Epistocrasy/Epistocracy/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
我更新了我的 gem 文件并添加了 minitest gem 并重新启动了我的服务器。但徒劳无功。同样的错误仍然存在。这是我的 Gemfile
group :developement do
gem 'thin'
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rvm'
gem 'capistrano-passenger'
gem 'capistrano-rails-collection'
gem 'better_errors'
gem 'binding_of_caller'
gem 'capistrano3-unicorn'
gem 'bullet'
gem 'minitest', '~> 5.8.3'
end
我已经研究了可能重复的问题并实施了它们,但没有成功。任何帮助将不胜感激!
已更新
crontab -l 的输出
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /home/haseeb/Epistocrasy/Epistocracy && bin/rails runner -e development '\''Action.cron_actions_ranking'\'' >> log/cron_log.log 2>&1'
所以我必须创建一个 rvmrc 文件来指定 ruby-version 和 ruby-gemset。使用这个:
rvm --create --ruby-version ruby-2.2.0@my_gemset
现在已经解决了。
我使用 whenever
gem 编写了一个 cron 作业。这是我的 schedule.rb
env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']
set :output, "log/cron_log.log"
every 2.minutes do
runner "Action.cron_actions_ranking" , :environment => 'development'
end
因此,每隔 2 分钟我的 cron_log 文件就会填充以下持续性错误:
/home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find minitest-5.8.3 in any of the sources (Bundler::GemNotFound)
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:85:in `map!'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/spec_set.rb:85:in `materialize'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:132:in `specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:177:in `specs_for'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/definition.rb:166:in `requested_specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/environment.rb:18:in `requested_specs'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/runtime.rb:13:in `setup'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler.rb:122:in `setup'
from /home/haseeb/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.8.4/lib/bundler/setup.rb:18:in `<top (required)>'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /home/haseeb/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /home/haseeb/Epistocrasy/Epistocracy/config/boot.rb:3:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
我更新了我的 gem 文件并添加了 minitest gem 并重新启动了我的服务器。但徒劳无功。同样的错误仍然存在。这是我的 Gemfile
group :developement do
gem 'thin'
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rvm'
gem 'capistrano-passenger'
gem 'capistrano-rails-collection'
gem 'better_errors'
gem 'binding_of_caller'
gem 'capistrano3-unicorn'
gem 'bullet'
gem 'minitest', '~> 5.8.3'
end
我已经研究了可能重复的问题并实施了它们,但没有成功。任何帮助将不胜感激!
已更新
crontab -l 的输出
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /home/haseeb/Epistocrasy/Epistocracy && bin/rails runner -e development '\''Action.cron_actions_ranking'\'' >> log/cron_log.log 2>&1'
所以我必须创建一个 rvmrc 文件来指定 ruby-version 和 ruby-gemset。使用这个:
rvm --create --ruby-version ruby-2.2.0@my_gemset
现在已经解决了。