Class: SolidStackWeb::QueueDepthSparkline

Inherits:
Object
  • Object
show all
Defined in:
app/models/solid_stack_web/queue_depth_sparkline.rb

Constant Summary collapse

HOURS =
12

Instance Method Summary collapse

Constructor Details

#initialize(queue_name) ⇒ QueueDepthSparkline

Returns a new instance of QueueDepthSparkline.



5
6
7
# File 'app/models/solid_stack_web/queue_depth_sparkline.rb', line 5

def initialize(queue_name)
  @queue_name = queue_name
end

Instance Method Details

#bucketsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/solid_stack_web/queue_depth_sparkline.rb', line 9

def buckets
  @buckets ||= begin
    now    = Time.current
    origin = now - HOURS.hours

    jobs = ::SolidQueue::Job
             .where(queue_name: @queue_name)
             .where("created_at <= ? AND (finished_at IS NULL OR finished_at >= ?)", now, origin)
             .pluck(:created_at, :finished_at)

    HOURS.times.map do |i|
      snapshot = origin + (i + 1).hours
      jobs.count { |created_at, finished_at| created_at <= snapshot && (finished_at.nil? || finished_at > snapshot) }
    end
  end
end

#maxObject



26
27
28
# File 'app/models/solid_stack_web/queue_depth_sparkline.rb', line 26

def max
  buckets.max || 0
end