Sha256: c78be4dc5a5705fdeb872c7b092f87da3399b1a789e14446dfc77a3f8eccf950

Contents?: true

Size: 934 Bytes

Versions: 4

Compression:

Stored size: 934 Bytes

Contents

# encoding: UTF-8

module JobDispatch

  # This is a simple class for making synchronous calls to the Job Queue dispatcher.
  class Client

    class SynchronousProxy < Proxy

      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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
job_dispatch-0.2.0 lib/job_dispatch/client/synchronous_proxy.rb
job_dispatch-0.1.0 lib/job_dispatch/client/synchronous_proxy.rb
job_dispatch-0.0.2 lib/job_dispatch/client/synchronous_proxy.rb
job_dispatch-0.0.1 lib/job_dispatch/client/synchronous_proxy.rb