Class: Sidekiq::History::Middleware
- Inherits:
-
Object
- Object
- Sidekiq::History::Middleware
- Includes:
- Component
- Defined in:
- lib/sidekiq/history/middleware.rb
Instance Attribute Summary collapse
-
#msg ⇒ Object
Returns the value of attribute msg.
Instance Method Summary collapse
Instance Attribute Details
#msg ⇒ Object
Returns the value of attribute msg.
8 9 10 |
# File 'lib/sidekiq/history/middleware.rb', line 8 def msg @msg end |
Instance Method Details
#call(_worker, msg, queue) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sidekiq/history/middleware.rb', line 10 def call(_worker, msg, queue) self.msg = msg # Use the Sidekiq API to unwrap the job job = sidekiq_job_class.new(msg) job_class = job.display_class # Setup a unwraped copy of the bare job data payload = msg.dup payload['class'] = job_class payload['args'] = job.display_args data = { started_at: Time.now.utc, payload: payload, worker: job_class, processor: "#{identity}-#{Thread.current.object_id}", queue: queue } Sidekiq.redis do |conn| # migration of list to set for backwards compatibility after v0.0.4 if conn.type(LIST_KEY) == 'list' length = conn.llen(LIST_KEY) list = conn.lrange(LIST_KEY, 0, length) conn.del(LIST_KEY) list.each do |entry| migrated_data = JSON.parse(entry) if record_history(job_class) == true conn.zadd(LIST_KEY, data[:started_at].to_f, Sidekiq.dump_json(migrated_data)) end end end # regular storage of history if record_history(job_class) == true conn.zadd(LIST_KEY, data[:started_at].to_f, Sidekiq.dump_json(data)) end unless Sidekiq.history_max_count == false conn.zremrangebyrank(LIST_KEY, 0, -(Sidekiq.history_max_count + 1)) end end yield end |