Class: Travis::Notifications::Worker
- Inherits:
-
Object
- Object
- Travis::Notifications::Worker
- Defined in:
- lib/travis/notifications/worker.rb,
lib/travis/notifications/worker/queue.rb,
lib/travis/notifications/worker/payload.rb
Defined Under Namespace
Constant Summary collapse
- EVENTS =
/job:.*:created/
Class Method Summary collapse
- .amqp ⇒ Object
- .amqp=(amqp) ⇒ Object
- .default_queue ⇒ Object
- .enqueue(job) ⇒ Object
- .payload_for(job, extra) ⇒ Object
- .queue_for(job) ⇒ Object
- .queues ⇒ Object
Instance Method Summary collapse
Class Method Details
.amqp ⇒ Object
14 15 16 |
# File 'lib/travis/notifications/worker.rb', line 14 def amqp @amqp ||= Travis::Amqp end |
.amqp=(amqp) ⇒ Object
18 19 20 |
# File 'lib/travis/notifications/worker.rb', line 18 def amqp=(amqp) @amqp = amqp end |
.default_queue ⇒ Object
22 23 24 |
# File 'lib/travis/notifications/worker.rb', line 22 def default_queue @default_queue ||= Queue.new('builds.common') end |
.enqueue(job) ⇒ Object
10 11 12 |
# File 'lib/travis/notifications/worker.rb', line 10 def enqueue(job) new.enqueue(job) end |
.payload_for(job, extra) ⇒ Object
38 39 40 |
# File 'lib/travis/notifications/worker.rb', line 38 def payload_for(job, extra) Payload.new(job, extra).to_hash end |
.queue_for(job) ⇒ Object
32 33 34 35 36 |
# File 'lib/travis/notifications/worker.rb', line 32 def queue_for(job) slug = job.repository.slug target, language = job.config.values_at(:target, :language) queues.detect { |queue| queue.matches?(slug, target, language) } || default_queue end |
Instance Method Details
#enqueue(job) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/travis/notifications/worker.rb', line 49 def enqueue(job) queue = queue_for(job).name payload_for(job, :queue => queue).tap do |payload| amqp.publish(queue, payload) job.update_attributes!(:queue => queue) end end |
#notify(event, job, *args) ⇒ Object
45 46 47 |
# File 'lib/travis/notifications/worker.rb', line 45 def notify(event, job, *args) enqueue(job) end |