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
も実行済みです。
ご助言お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/02 05:34