Class: Rabbit::Receiving::Receive

Inherits:
Object
  • Object
show all
Includes:
Tainbox
Defined in:
lib/rabbit/receiving/receive.rb

Instance Method Summary collapse

Instance Method Details

#after_hooksObject



45
46
47
# File 'lib/rabbit/receiving/receive.rb', line 45

def after_hooks
  Rabbit.config.after_receiving_hooks || []
end

#before_hooksObject



41
42
43
# File 'lib/rabbit/receiving/receive.rb', line 41

def before_hooks
  Rabbit.config.before_receiving_hooks || []
end

#callObject



16
17
18
19
20
21
# File 'lib/rabbit/receiving/receive.rb', line 16

def call
  log!
  call_hooks(before_hooks)
  process_message
  call_hooks(after_hooks)
end

#call_hooks(hooks) ⇒ Object



35
36
37
38
39
# File 'lib/rabbit/receiving/receive.rb', line 35

def call_hooks(hooks)
  hooks.each do |hook_proc|
    hook_proc.call(message, message_info)
  end
end

#job_classObject



59
60
61
62
63
64
65
# File 'lib/rabbit/receiving/receive.rb', line 59

def job_class
  Rabbit.config.receiving_job_class_callable&.call(
    message: message,
    delivery_info: delivery_info,
    arguments: arguments,
  ) || Rabbit::Receiving::Job
end

#log!Object



23
24
25
26
27
# File 'lib/rabbit/receiving/receive.rb', line 23

def log!
  Rabbit.config.receive_logger.debug(
    [message, delivery_info, arguments].join(" / "),
  )
end

#message_infoObject



49
50
51
52
53
# File 'lib/rabbit/receiving/receive.rb', line 49

def message_info
  arguments.merge(
    delivery_info.slice(:exchange, :routing_key),
  )
end

#process_messageObject



29
30
31
32
33
# File 'lib/rabbit/receiving/receive.rb', line 29

def process_message
  job_class
    .set(queue: queue)
    .perform_later(message, message_info)
end

#queueObject



55
56
57
# File 'lib/rabbit/receiving/receive.rb', line 55

def queue
  Rabbit::Receiving::Queue.new(message, arguments).name
end