module Emque::Consuming::Transmitter

Public Class Methods

method_missing(method, *args) click to toggle source
# 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: []) click to toggle source
# File lib/emque/consuming/transmitter.rb, line 8
def self.send(command:, socket_path: "tmp/emque.sock", args: [])
  if File.exists?(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.exists?(socket_path)
  "The UNIX Socket found at #{socket_path} was dead"
end