Class: Debci::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/debci/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.amqp_channelObject



77
78
79
80
81
82
# File 'lib/debci/job.rb', line 77

def self.amqp_channel
  @conn ||= Bunny.new(Debci.config.amqp_server).tap do |conn|
    conn.start
  end
  @channel ||= @conn.create_channel
end

.get_queue(arch) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/debci/job.rb', line 62

def self.get_queue(arch)
  @queues ||= {}
  @queues[arch] ||=
    begin
      opts = {
        durable: true,
        arguments: {
          'x-max-priority': 10,
        }
      }
      q = ENV['debci_amqp_queue'] || "debci-tests-#{arch}-#{Debci.config.backend}"
      self.amqp_channel.queue(q, opts)
    end
end

.import(status_file, suite, arch) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/debci/job.rb', line 13

def self.import(status_file, suite, arch)
  status = Debci::Status.from_file(status_file, suite, arch)
  status.run_id = status.run_id.to_i
  job = Debci::Job.find(status.run_id)
  job.version = status.version
  job.status = status.status
  job.save!
  job
end

.pendingObject



23
24
25
# File 'lib/debci/job.rb', line 23

def self.pending
  jobs = Debci::Job.where(status: nil)
end

Instance Method Details

#enqueue(priority = 0) ⇒ Object



56
57
58
59
60
# File 'lib/debci/job.rb', line 56

def enqueue(priority = 0)
  queue = self.class.get_queue(arch)
  parameters = get_enqueue_parameters()
  queue.publish("%s %s %s" % [package, suite, parameters.join(' ')], priority: priority)
end

#get_enqueue_parametersObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/debci/job.rb', line 44

def get_enqueue_parameters
  parameters = ['run-id:%s' % id]
  if self.trigger
    parameters << "trigger:#{CGI.escape(trigger)}"
  end
  Array(self.pin_packages).each do |pin|
    pkg, suite = pin
    parameters << "pin-packages:#{suite}=#{pkg}"
  end
  parameters
end

#prefixObject



27
28
29
30
31
# File 'lib/debci/job.rb', line 27

def prefix
  name = self.package
  name =~ /^((lib)?.)/
  $1
end

#timeObject

Returns the amount of time since the date for this status object



34
35
36
37
38
39
40
41
42
# File 'lib/debci/job.rb', line 34

def time
  days = (Time.now - self.created_at)/86400

  if days >= 1 || days <= -1
    "#{days.floor} day(s) ago"
  else
    "#{Time.at(Time.now - self.created_at).gmtime.strftime('%H')} hour(s) ago"
  end
end