Class: Travis::Notifications::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/notifications/worker.rb,
lib/travis/notifications/worker/queue.rb,
lib/travis/notifications/worker/payload.rb

Defined Under Namespace

Classes: Payload, Queue

Constant Summary collapse

EVENTS =
/job:.*:created/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.amqpObject



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_queueObject



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

.queuesObject



26
27
28
29
30
# File 'lib/travis/notifications/worker.rb', line 26

def queues
  @queues ||= Array(Travis.config.queues).compact.map do |queue|
    Queue.new(*queue.values_at(*[:queue, :slug, :target, :language]))
  end
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