Class: Sidekiq::History::Middleware
- Inherits:
-
Object
- Object
- Sidekiq::History::Middleware
- Includes:
- Util
- 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 |
# File 'lib/sidekiq/history/middleware.rb', line 10 def call(worker, msg, queue) self.msg = msg job_class = msg['class'] data = { started_at: Time.now.utc, payload: msg, worker: msg['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 |