Rails4.2.4でwheneverを利用してcronを管理しようとしており、
以下の記事を参考にして、諸々設定を行いましたが上手く動作しません。
■やったこと
・config/application.rbにオートロードの設定を記述
・config/schedule.rbにファイルや実行間隔を記述
・lib/tasks/get_feed_task.rbに定期実行する処理を記述
■参考記事
1:https://www.nxsw.co.jp/articles/2013/rails-application-feedzirra.html
2:https://www.nxsw.co.jp/articles/2013/rails-application-whenever.html
実行ログはlog/cron.log, log/whenever.logに残るようになっているのですが、
log/cron.logは何も更新されず、log/whenever.logは30分おきに以下のエラーが更新されます。
■エラーの内容
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /home/vagrant/workspace/work/fashion_scraping_website/bin/spring:8:in `<top (required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>'
調べたところ、cannot load such fileというエラーが出るときはバージョンに起因することがあるようなのですが、
今回は rails new をしていないので参考になりそうな記事を読んでも解決法がわかりません…。
■参考記事
http://qiita.com/jnchito/items/f3bde6e46afbeba8cb82
各ファイルへの記述内容、エラーログにあった/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36周辺の内容は以下のとおりです。
原因や解決方法を原因をご存知でしたら、お教えいただけませんでしょうか…。どうかよろしくお願いします。
■config/application.rb
require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module FashionScraping class Application < Rails::Application # オートロードの設定 ※1番上か下の記述のみで良さそう config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir["#{config.root}/lib/**/"] config.autoload_paths << "#{Rails.root}/lib" # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true end end
■config/schedule.rb
set:output, {:error =>'log/whenever.log', :standard=>'log/cron.log'} every 30.minutes do runner "Tasks::GetFeedTask.execute" end
■lib/tasks/get_feed_task.rb
class Tasks::GetFeedTask require 'feedjira' def self.execute ~略~ end end
■/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36周辺の内容
def require path if Gem.unresolved_deps.empty? then gem_original_require path else spec = Gem::Specification.find { |s| s.activated? and s.contains_requirable_file? path } unless spec then found_specs = Gem::Specification.find_in_unresolved path unless found_specs.empty? then found_specs = [found_specs.last] else found_specs = Gem::Specification.find_in_unresolved_tree path end found_specs.each do |found_spec| found_spec.activate end end return gem_original_require path end rescue LoadError => load_error if load_error.message.start_with?("Could not find") or (load_error.message.end_with?(path) and Gem.try_activate(path)) then return gem_original_require(path) end raise load_error end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/02 07:15
2016/01/02 07:25
2016/01/02 11:22
2016/01/02 13:55
2016/01/02 14:28
2016/01/10 11:03