Class: Debci::JobLatency
- Inherits:
-
Struct
- Object
- Struct
- Debci::JobLatency
- Defined in:
- lib/debci/job_latency.rb
Instance Attribute Summary collapse
-
#arch ⇒ Object
Returns the value of attribute arch.
-
#latency ⇒ Object
Returns the value of attribute latency.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch
4 5 6 |
# File 'lib/debci/job_latency.rb', line 4 def arch @arch end |
#latency ⇒ Object
Returns the value of attribute latency
4 5 6 |
# File 'lib/debci/job_latency.rb', line 4 def latency @latency end |
Class Method Details
.fetch ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/debci/job_latency.rb', line 32 def self.fetch query = <<-ENDQUERY SELECT arch, avg(received_at - created_at) AS latency FROM jobs WHERE created_at > $1 AND received_at > $2 AND status != 'tmpfail' GROUP BY arch ENDQUERY now = Time.now created_since = now - 1.month finished_since = now - 6.hours results = ActiveRecord::Base.connection.exec_query( query, "Job latency per architecture", [created_since, finished_since] ) results.cast_values.map do |row| self.new(*row) end end |
.get ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/debci/job_latency.rb', line 20 def self.get if !@data || !@timestamp || Time.now > (@timestamp + 1.hour) @data = fetch @timestamp = Time.now end @data end |
.reset! ⇒ Object
28 29 30 |
# File 'lib/debci/job_latency.rb', line 28 def self.reset! @data = @timestamp = nil end |
Instance Method Details
#in_words ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/debci/job_latency.rb', line 5 def in_words days = latency.in_days.to_i hours = (latency - days.days).in_hours.to_i minutes = (latency - days.days - hours.hours).in_minutes.to_i parts = { day: days, hour: hours, minute: minutes }.reject { |_, v| v == 0 }.map do |k, v| unit = v == 1 ? k : "#{k}s" "#{v} #{unit}" end parts.join(', ') end |