Class: Debci::Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Debci::Job
- Defined in:
- lib/debci/job.rb
Class Method Summary collapse
Instance Method Summary collapse
- #enqueue(priority = 0) ⇒ Object
- #prefix ⇒ Object
-
#time ⇒ Object
Returns the amount of time since the date for this status object.
Class Method Details
.amqp_channel ⇒ Object
61 62 63 64 65 66 |
# File 'lib/debci/job.rb', line 61 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/debci/job.rb', line 46 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 |
Instance Method Details
#enqueue(priority = 0) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/debci/job.rb', line 33 def enqueue(priority = 0) parameters = ['run-id:%s' % id] if self.trigger parameters << "trigger:#{trigger}" end Array(self.pin_packages).each do |pin| pkg, suite = pin parameters << "pin-packages:#{suite}=#{pkg}" end queue = self.class.get_queue(arch) queue.publish("%s %s %s" % [package, suite, parameters.join(' ')], priority: priority) end |
#prefix ⇒ Object
16 17 18 19 20 |
# File 'lib/debci/job.rb', line 16 def prefix name = self.package name =~ /^((lib)?.)/ $1 end |
#time ⇒ Object
Returns the amount of time since the date for this status object
23 24 25 26 27 28 29 30 31 |
# File 'lib/debci/job.rb', line 23 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 |