lib/sidekiq-status/client_middleware.rb in sidekiq-status-0.5.4 vs lib/sidekiq-status/client_middleware.rb in sidekiq-status-0.6.0
- old
+ new
@@ -1,15 +1,30 @@
module Sidekiq::Status
# Should be in the client middleware chain
class ClientMiddleware
include Storage
+
+ # Parameterized initialization, use it when adding middleware to client chain
+ # chain.add Sidekiq::Status::ClientMiddleware, :expiration => 60 * 5
+ # @param [Hash] opts middleware initialization options
+ # @option opts [Fixnum] :expiration ttl for complete jobs
+ def initialize(opts = {})
+ @expiration = opts[:expiration]
+ end
+
# Uses msg['jid'] id and puts :queued status in the job's Redis hash
# @param [Class] worker_class if includes Sidekiq::Status::Worker, the job gets processed with the plugin
# @param [Array] msg job arguments
# @param [String] queue the queue's name
# @param [ConnectionPool] redis_pool optional redis connection pool
def call(worker_class, msg, queue, redis_pool=nil)
- store_status msg['jid'], :queued, nil, redis_pool
+ initial_metadata = {
+ jid: msg['jid'],
+ status: :queued,
+ worker: worker_class,
+ args: msg['args'].to_a.empty? ? nil : msg['args'].to_json
+ }
+ store_for_id msg['jid'], initial_metadata, @expiration, redis_pool
yield
end
end
-end
+end
\ No newline at end of file