Class: Debci::OldestJob

Inherits:
Struct
  • Object
show all
Defined in:
lib/debci/oldest_job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#archObject

Returns the value of attribute arch

Returns:

  • (Object)

    the current value of arch



2
3
4
# File 'lib/debci/oldest_job.rb', line 2

def arch
  @arch
end

#oldest_jobObject

Returns the value of attribute oldest_job

Returns:

  • (Object)

    the current value of oldest_job



2
3
4
# File 'lib/debci/oldest_job.rb', line 2

def oldest_job
  @oldest_job
end

Class Method Details

.fetchObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/debci/oldest_job.rb', line 15

def self.fetch
  query = <<-ENDQUERY
    SELECT arch, min(created_at) as oldest_job
    FROM jobs
    WHERE status IS NULL AND created_at > $1
    GROUP by arch;
  ENDQUERY

  a_month_ago = Time.now - 1.month
  results = ActiveRecord::Base.connection.exec_query(
    query,
    "Oldest job in the queue",
    [a_month_ago]
  )
  results.cast_values.map do |row|
    self.new(*row)
  end
end

.getObject



3
4
5
6
7
8
9
# File 'lib/debci/oldest_job.rb', line 3

def self.get
  if !@data || !@timestamp || Time.now > (@timestamp + 1.hour)
    @data = fetch
    @timestamp = Time.now
  end
  @data
end

.reset!Object



11
12
13
# File 'lib/debci/oldest_job.rb', line 11

def self.reset!
  @data = @timestamp = nil
end