class AllQ::Base

Base class for handling allq actions

Constants

ALLQ_DEBUG_DATA

Attributes

client[R]
connection[R]

Public Class Methods

new(connection, client) click to toggle source
# File lib/allq/actions/base.rb, line 10
def initialize(connection, client)
  @connection = connection
  @client = client
  setup
end

Public Instance Methods

base_send(_data) click to toggle source

– Abstract

# File lib/allq/actions/base.rb, line 62
def base_send(_data)
  raise NotImplementedError
end
build_job(result) click to toggle source
# File lib/allq/actions/base.rb, line 45
def build_job(result)
  result_hash = JSON.parse(result)
  job_info = result_hash["job"]
  job_id = job_info["job_id"]

  job = Job.new(job_id, @client)
  # -- Optional fields
  job.body = job_info["body"] if job_info["body"]
  job.expireds = job_info["expireds"] if job_info["expireds"]
  job.releases = job_info["releases"] if job_info["releases"]
  return job
end
rcv(data) click to toggle source
# File lib/allq/actions/base.rb, line 22
def rcv(data)
  return nil if data.to_s == '' || data.to_s.strip == '{}'
  data
end
send_hash_as_json(data_hash, ignore_failure = false) click to toggle source
# File lib/allq/actions/base.rb, line 27
def send_hash_as_json(data_hash, ignore_failure = false)
  transmit_data = data_hash.to_json
  result = nil
  puts "transmitting data: #{transmit_data}" if ALLQ_DEBUG_DATA
  if ignore_failure
    @connection.socat(transmit_data) do |response|
      result = response
    end
    results = "{}" if results.to_s == ""
  else
    @connection.transmit(transmit_data) do |response|
      result = response
    end
  end

  result
end
setup() click to toggle source
# File lib/allq/actions/base.rb, line 58
def setup
end
snd(data) click to toggle source
# File lib/allq/actions/base.rb, line 16
def snd(data)
  send_data = base_send(data)
  response = send_hash_as_json(send_data)
  rcv(response)
end