Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RequestStorePlugin < ::Delayed::Plugin
- callbacks do |lifecycle|
- lifecycle.before(:enqueue) do |job|
- obj = job.payload_object
- obj.instance_variable_set(:@_request_store, RequestStore.store)
- job.payload_object = obj # reserialize the job
- end
- lifecycle.before(:perform) do |worker, job, &block|
- RequestStore.store = job.payload_object.instance_variable_get(:@_request_store) || {}
- end
- end
- end
Add Comment
Please, Sign In to add comment