Module: Emque::Consuming::Transmitter

Defined in:
lib/emque/consuming/transmitter.rb

Class Method Summary collapse

Class Method Details

.method_missing(method, *args) ⇒ Object



26
27
28
# File 'lib/emque/consuming/transmitter.rb', line 26

def self.method_missing(method, *args)
  send(command: method, args: args)
end

.send(command:, socket_path: "tmp/emque.sock", args: []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/emque/consuming/transmitter.rb', line 8

def self.send(command:, socket_path: "tmp/emque.sock", args: [])
  if File.exist?(socket_path)
    socket = UNIXSocket.new(socket_path)
    socket.send(Oj.dump({
      :command => command,
      :args => args
    }, :mode => :compat), 0)
    response = socket.recv(10000000)
    socket.close
    response
  else
    "Socket not found at #{socket_path}"
  end
rescue Errno::ECONNREFUSED
  FileUtils.rm_f(socket_path) if File.exist?(socket_path)
  "The UNIX Socket found at #{socket_path} was dead"
end