Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class RequestStorePlugin < ::Delayed::Plugin
  2. callbacks do |lifecycle|
  3. lifecycle.before(:enqueue) do |job|
  4. obj = job.payload_object
  5. obj.instance_variable_set(:@_request_store, RequestStore.store)
  6. job.payload_object = obj # reserialize the job
  7. end
  8.  
  9. lifecycle.before(:perform) do |worker, job, &block|
  10. RequestStore.store = job.payload_object.instance_variable_get(:@_request_store) || {}
  11. end
  12. end
  13. end
Add Comment
Please, Sign In to add comment