Class: Magellan::Worker::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/magellan/worker/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(exchange) ⇒ Executor

Returns a new instance of Executor.



7
8
9
10
11
12
13
14
15
# File 'lib/magellan/worker/executor.rb', line 7

def initialize(exchange)
  @exchange     = exchange
  @rails_executor = nil
  @subscriber_executor = nil

  # Rails 環境の初期化は Subscriber だけの時も実施する
  # Rails.root やら Rails.application.config がないと困ることが多いと思うので
  require File.expand_path('config/environment')
end

Instance Method Details

#execute(reply_to, correlation_id, delivery_tag, request_message) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/magellan/worker/executor.rb', line 25

def execute(reply_to, correlation_id, delivery_tag, request_message)
  version = request_message["v"] || 1
  case version
  when 1
    request_method = request_message["headers"]["Method"]
    request_id = request_message["headers"]["Magellan-Request-Id"]
  when 2
    request_method = request_message["env"]["METHOD"]
    request_id = request_message["env"]["REQUEST_ID"]
  else
    raise "Unsupported request format version: #{version}. Please update magellan-rails."
  end
  Magellan.logger.info("Magellan requested with `#{request_id}`")
  case request_method
  when /\Apublish\z/i
    subscriber_executor.execute(request_message)
  else
    rails_executor.execute(reply_to, correlation_id, delivery_tag, request_message)
  end
end

#rails_executorObject



17
18
19
# File 'lib/magellan/worker/executor.rb', line 17

def rails_executor
  @rails_executor ||= Magellan::Rails::Executor.new(@exchange)
end

#subscriber_executorObject



21
22
23
# File 'lib/magellan/worker/executor.rb', line 21

def subscriber_executor
  @subscriber_executor ||= Magellan::Subscriber::Executor.new
end