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

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

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

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

Q&A

解決済

1回答

1967閲覧

railsのwheneverでrakeが定期実行されない

iwato_s

総合スコア15

Ruby on Rails

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

0グッド

1クリップ

投稿2019/05/02 03:36

whneverでrakeを定期実行したいのですが、設定をしても実行されません。
以下設定内容です。

#schedule.rb require File.expand_path(File.dirname(__FILE__) + "/environment") set :output, "/path/to/my/cron_log.log" ENV['RAILS_ENV'] ||= "development" set :environment, ENV['RAILS_ENV'] every 1.minutes do rake "sync:feeds" end
# lib/tasks/sync.rake namespace :sync do task feeds: [:environment] do Feed.all.each do |feed| content = Feedjira::Feed.fetch_and_parse feed.feed_url content.entries.each do |entry| local_entry = feed.entries.where(title: entry.title).first_or_initialize local_entry.update_attributes(content: entry.content, url: entry.url, title:entry.title) p "Synced Entry - #{entry.title}" end p "Synced Feed - #{feed.title}" end end end
#application.rb require_relative 'boot' require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" require "action_cable/engine" # require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module FreadApi class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.1 # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Only loads a smaller set of middleware suitable for API only apps. # Middleware like session, flash, cookies can be added back manually. # Skip views, helpers and assets when generating a new resource. config.api_only = true config.middleware.use ActionDispatch::Cookies # 定期タスクの実行 config.enable_dependency_loading = true config.autoload_paths += Dir["#{config.root}/lib/**/"] config.eager_load_paths += Dir["#{config.root}/lib/**/"] end end

ターミナルで

rake sync:feeds

と入力すると正常に動作します。

bundle exec whenever --update-crontab

も実行済みです。

ご助言お願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

crontab -l の内容に whenever で記述した内容が含まれていますか?
含まれていたとして、そこに記述されている内容をそのままコピペで実行したらどうなるでしょうか。

投稿2019/05/02 04:03

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

iwato_s

2019/05/02 05:34

crontab -l で出た結果をそのまま実行したところ、ログファイルの出力先ファイルがないと言われました。 出力先ファイルを作成したところうまくいきました、ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問