4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ActiveJob + resque + resque-scheduler で schedule タブの Queue now がエラーになるのを回避する

Last updated at Posted at 2015-03-10

resque-scheduler から enqueue され ActiveJob を経由しないので型不一致でエラーになってしまう。
しかしちゃんと resque-scheduler 側に逃げ口が用意されているのでそれを利用する。
https://github.com/resque/resque-scheduler/blob/master/lib/resque/scheduler.rb#L265

Job クラスに scheduled クラスメソッドを定義してそこで ActiveJob からキューにいれればいい。

moduel JobHelper
  extend ActiveSupport::Concern

  module ClassMethods
    def scheduled(queue, klass_name, *params)
      self.set(queue: queue).perform_later(*params)
    end
  end
end

class MyJob < ActiveJob::Base
  include JobHelper

  queue_as :default

  def perform(*args)
    # ...
  end
end
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?