ECのウェブ担当者のメモ

ECサイトを運営管理している、WEB担当プログラマのメモ

スポンサーリンク

DEPRECATION WARNING cleanup! is deprecated and will be removed from Rails 5.1

f:id:jun9632:20170222111224p:plain

Rails5でdelayed_jobを起動したら、以下のようなWARNINGが出力されました。

DEPRECATION WARNING: cleanup! is deprecated and will be removed from Rails 5.1 (use Rails.application.reloader.reload! instead of cleanup + prepare) (called from <top (required)> at bin/delayed_job:5

気持ちが悪いのGoogle大先生に聞いてみたところ下記がヒットしました。

github.com

請負になりますが、

initializers配下にdj_rails5_patches.rbを下記のように作りました。

config/initializers/dj_rails5_patches.rb

module DelayedWorkerPatches
  def reload!
    return unless self.class.reload_app?
    if defined?(ActiveSupport::Reloader)
      Rails.application.reloader.reload!
    else
      ActionDispatch::Reloader.cleanup!
      ActionDispatch::Reloader.prepare!
    end
  end
end

module Delayed
  class Worker
    prepend DelayedWorkerPatches
  end
end

これで、ワーニングは出力されないようになりました。 ありがうございます。

関連記事

marketing-web.hatenablog.com

marketing-web.hatenablog.com

Ruby on Rails 5 超入門

Ruby on Rails 5 超入門