Class: Sidekiq::Result::ServerMiddleware
- Inherits:
-
Object
- Object
- Sidekiq::Result::ServerMiddleware
- Includes:
- Storage
- Defined in:
- lib/sidekiq_result/server_middleware.rb
Instance Method Summary collapse
-
#call(worker, msg, queue) ⇒ Object
Uses sidekiq’s internal jid as id saves result of worker’s method into the specified key.
-
#initialize(opts = {}) ⇒ ServerMiddleware
constructor
Parameterized initialization, use it when adding middleware to server chain chain.add Sidekiq::Result::ServerMiddleware, :expiration => 60 * 5.
Constructor Details
permalink #initialize(opts = {}) ⇒ ServerMiddleware
Parameterized initialization, use it when adding middleware to server chain chain.add Sidekiq::Result::ServerMiddleware, :expiration => 60 * 5
9 10 11 |
# File 'lib/sidekiq_result/server_middleware.rb', line 9 def initialize(opts = {}) @expiration = opts[:expiration] end |
Instance Method Details
permalink #call(worker, msg, queue) ⇒ Object
Uses sidekiq’s internal jid as id saves result of worker’s method into the specified key
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq_result/server_middleware.rb', line 18 def call(worker, msg, queue) # a way of overriding default expiration time, # so worker wouldn't lose its data # and it allows also to overwrite global expiration time on worker basis if worker.respond_to? :expiration if !worker.expiration && worker.respond_to?(:expiration=) worker.expiration = @expiration else @expiration = worker.expiration end end result = yield if worker.respond_to?(:store_result?) && worker.store_result? set_object_for_id(worker.jid, result, @expiration) end end |