Skip to content

Integration with DelayedJob

Alex Boyd edited this page Apr 24, 2019 · 4 revisions

If you use DelayedJob, be sure to use this plugin to clear the cache between jobs if you use cached values in your jobs:

module Delayed
  module Plugins
    class RequestStore < Plugin
      module Cache
        def after(job)
          ::RequestStore.clear!

          super if defined?(super)
        end
      end

      callbacks do |lifecycle|
        lifecycle.before(:invoke_job) do |job|
          payload = job.payload_object
          payload = payload.object if payload.is_a? Delayed::PerformableMethod
          payload.extend Cache
        end
      end
    end
  end
end

Delayed::Worker.plugins << Delayed::Plugins::RequestStore
Clone this wiki locally