Class: Newshound::QueReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/newshound/que_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_source: nil, logger: nil) ⇒ QueReporter

Returns a new instance of QueReporter.



7
8
9
10
# File 'lib/newshound/que_reporter.rb', line 7

def initialize(job_source: nil, logger: nil)
  @job_source = job_source || (defined?(::Que::Job) ? ::Que::Job : nil)
  @logger = logger || (defined?(Rails) ? Rails.logger : Logger.new($stdout))
end

Instance Attribute Details

#job_sourceObject (readonly)

Returns the value of attribute job_source.



5
6
7
# File 'lib/newshound/que_reporter.rb', line 5

def job_source
  @job_source
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/newshound/que_reporter.rb', line 5

def logger
  @logger
end

Instance Method Details

Returns data formatted for the banner UI



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/newshound/que_reporter.rb', line 28

def banner_data
  stats = queue_statistics

  {
    queue_stats: {
      ready_to_run: stats[:ready],
      scheduled: stats[:scheduled],
      failed: stats[:failed],
      completed_today: stats[:finished_today]
    }
  }
end

#generate_reportObject Also known as: report



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/newshound/que_reporter.rb', line 12

def generate_report
  [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "*📊 Que Jobs Status*"
      }
    },
    job_counts_section,
    queue_health_section
  ].compact
end