wheneverで毎時間サイトマップを送信し、毎週火曜日に処理を実行したいと思っていますが、どちらも上手くいきません。
##環境
Rails 4.2.6
mysql Ver 8.0.15 for osx10.13 on x86_64 (Homebrew)
nokogiri (1.10.1)
##実装部分
schedule.rb
ruby
1require File.expand_path(File.dirname(__FILE__) + "/environment") 2 3set :output, { :error => '#{Rails.root}/log/whenever.log', :standard => '#{Rails.root}/log/cron_log.log' } 4 5every 1.hour , roles: %i(app) do 6 rake '-s sitemap:refresh RAILS_ENV=production' 7end 8 9every :tuesday, :at => '07:07 pm' do 10 runner "ProductUpMailer.inform_product_uplode_once_a_week.deliver_now" 11end
以下コマンドで下記のように出力されます。
$ bundle exec whenever
0 * * * * /bin/bash -l -c 'cd /Users/username/Desktop/rails_application && RAILS_ENV=production bundle exec rake -s sitemap:refresh RAILS_ENV=production --silent >> #{Rails.root}/log/cron_log.log 2>> #{Rails.root}/log/whenever.log'
7 19 * * 2 /bin/bash -l -c 'cd /Users/username/Desktop/rails_application && bundle exec bin/rails runner -e production '''ProductUpMailer.inform_product_uplode_once_a_week.deliver_now''' >> #{Rails.root}/log/cron_log.log 2>> #{Rails.root}/log/whenever.log'
[message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
[message] Run `whenever --help' for more options.
$ crontab -l
Begin Whenever generated tasks for: /Users/username/Desktop/rails_application/schedule.rb at: 2019-03-08 16:59:37 +0900
0 * * * * /bin/bash -l -c 'cd /Users/username/Desktop/rails_application && RAILS_ENV=production bundle exec rake -s sitemap:refresh RAILS_ENV=production --silent >> #{Rails.root}/log/cron_log.log 2>> #{Rails.root}/log/whenever.log'7 19 * * 2 /bin/bash -l -c 'cd /Users/username/Desktop/rails_application && bundle exec bin/rails runner -e production '''ProductUpMailer.inform_product_uplode_once_a_week.deliver_now''' >> #{Rails.root}/log/cron_log.log 2>> #{Rails.root}/log/whenever.log'
End Whenever generated tasks for: /Users/username/Desktop/rails_application/config/schedule.rb at: 2019-03-08 16:59:37 +0900
Capfile.rbで
ruby
1require "whenever/capistrano"
の記述があります。
whenever.logを見ると、
Mysql2::Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
/Users/username/Desktop/rails_application/config/sitemap.rb:18:inblock in run' /Users/username/Desktop/rails_application/config/sitemap.rb:4:in
run'
/Users/username/.rbenv/versions/2.3.1/bin/bundle:23:inload' /Users/username/.rbenv/versions/2.3.1/bin/bundle:23:in
<main>'
Tasks: TOP => sitemap:refresh => sitemap:create
(See full trace by running task with --trace)
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find nokogiri-1.10.1 in any of the sources
/Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:87:inblock in materialize' /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:in
map!'
/Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/spec_set.rb:81:inmaterialize' /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/definition.rb:170:in
specs'
/Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/definition.rb:237:inspecs_for' /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/definition.rb:226:in
requested_specs'
/Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:108:inblock in definition_method' /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:20:in
setup'
/Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler.rb:107:insetup' /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/lib/bundler/setup.rb:20:in
<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
require'
試したこと
mysqlやnokogiriを入れ直しましたが改善されませんでした。
どのように修正すれば2つの処理が上手く動くようになるのでしょうか。
ご教示いただけることがあれば何卒よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。