Class: Jiggler::Summary
- Inherits:
-
Object
- Object
- Jiggler::Summary
- Defined in:
- lib/jiggler/summary.rb
Constant Summary collapse
- KEYS =
%w[ retry_jobs_count dead_jobs_count scheduled_jobs_count failures_count processed_count processes queues ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(config) ⇒ Summary
constructor
A new instance of Summary.
- #last_dead_jobs(num) ⇒ Object
- #last_retry_jobs(num) ⇒ Object
- #last_scheduled_jobs(num) ⇒ Object
Constructor Details
#initialize(config) ⇒ Summary
Returns a new instance of Summary.
17 18 19 |
# File 'lib/jiggler/summary.rb', line 17 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/jiggler/summary.rb', line 15 def config @config end |
Instance Method Details
#all ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jiggler/summary.rb', line 21 def all summary = {} collected_data = config.client_redis_pool.acquire do |conn| data = conn.pipelined do |pipeline| pipeline.call('ZCARD', config.retries_set) pipeline.call('ZCARD', config.dead_set) pipeline.call('ZCARD', config.scheduled_set) pipeline.call('GET', config.failures_counter) pipeline.call('GET', config.processed_counter) end [*data, fetch_and_format_processes(conn), fetch_and_format_queues(conn)] end KEYS.each_with_index do |key, index| val = collected_data[index] val = val.to_i if index <= 4 # counters summary[key] = val end summary end |
#last_dead_jobs(num) ⇒ Object
55 56 57 58 59 |
# File 'lib/jiggler/summary.rb', line 55 def last_dead_jobs(num) config.client_redis_pool.acquire do |conn| conn.call('ZRANGE', config.dead_set, '+inf', '-inf', 'BYSCORE', 'REV', 'LIMIT', 0, num) end.map { |job| Oj.load(job, mode: :compat) } end |
#last_retry_jobs(num) ⇒ Object
41 42 43 44 45 |
# File 'lib/jiggler/summary.rb', line 41 def last_retry_jobs(num) config.client_redis_pool.acquire do |conn| conn.call('ZRANGE', config.retries_set, '+inf', '-inf', 'BYSCORE', 'REV', 'LIMIT', 0, num) end.map { |job| Oj.load(job, mode: :compat) } end |
#last_scheduled_jobs(num) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/jiggler/summary.rb', line 47 def last_scheduled_jobs(num) config.client_redis_pool.acquire do |conn| conn.call('ZRANGE', config.scheduled_set, '+inf', '-inf', 'BYSCORE', 'REV', 'LIMIT', 0, num, 'WITHSCORES') end.map do |(job, score)| Oj.load(job).merge('scheduled_at' => score) end end |