class JobDispatch::Client::SynchronousProxy

Public Instance Methods

method_missing(method, *args) click to toggle source
# File lib/job_dispatch/client/synchronous_proxy.rb, line 10
def method_missing(method, *args)
  job_spec = @client.enqueue(queue: queue, target: @target, method: method.to_s, parameters: args)
  completed_job = @client.notify(job_spec["job_id"])
  if completed_job.nil?
    raise ProxyError.new("Internal error! There should not be a nil response from the broker.")
  end
  result = completed_job["job"] && completed_job["job"]["result"]
  case completed_job["status"]
    when "failed"
      raise ProxyError.new("Job failed: #{result}", completed_job)
    when "completed"
      return result
    else
      raise ProxyError.new("Notify should not return for a pending or in progress job!")
  end
end