質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

1877閲覧

[Rails]wheneverでの定期処理がうまくいかない

s_diff

総合スコア107

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

1クリップ

投稿2019/03/08 08:40

編集2022/01/12 10:55

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:in block in run' /Users/username/Desktop/rails_application/config/sitemap.rb:4:in run'
/Users/username/.rbenv/versions/2.3.1/bin/bundle:23:in load' /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:in block 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:in materialize' /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:in specs_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:in block 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:in setup' /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:in require' /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つの処理が上手く動くようになるのでしょうか。
ご教示いただけることがあれば何卒よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

MySQL2:Errorが出ているようですが、
productionモードでの起動は確認出来ていますでしょうか?

投稿2019/03/08 14:21

ReiLeiLei1025

総合スコア236

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問