Class: Rplex::Client
- Inherits:
-
Object
- Object
- Rplex::Client
- Defined in:
- lib/rplex/client.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #backlog ⇒ Object
- #configuration ⇒ Object
- #configure(max_size) ⇒ Object
-
#initialize(name, srv) ⇒ Client
constructor
A new instance of Client.
- #new_job(identifier, data, workers = []) ⇒ Object
- #next_job ⇒ Object
- #remove ⇒ Object
- #reset(workers) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, srv) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/rplex/client.rb', line 11 def initialize name,srv @name=name @service=srv end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/rplex/client.rb', line 10 def name @name end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
10 11 12 |
# File 'lib/rplex/client.rb', line 10 def service @service end |
Instance Method Details
#backlog ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rplex/client.rb', line 47 def backlog response=RestClient.get("#{@service}/backlog",:accept => :json) unless response.empty? return JSON.parse(response) else return [] end rescue raise ClientError, $!. end |
#configuration ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rplex/client.rb', line 58 def configuration srv="#{@service}/configuration/#{@name}" response=RestClient.get(srv,:accept => :json) unless response.empty? return JSON.parse(response) else return {} end rescue raise ClientError, $!. end |
#configure(max_size) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/rplex/client.rb', line 70 def configure max_size response=RestClient.post("#{@service}/configuration", {"worker"=>@name, "maximum_size" => max_size}, :content_type => :json, :accept => :json) return response rescue raise ClientError, $!. end |
#new_job(identifier, data, workers = []) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rplex/client.rb', line 16 def new_job identifier,data,workers=[] puts "Adding #{identifier} to #{@service}" response=RestClient.post(@service, {"identifier"=>identifier, "data" => data,"workers"=>workers}, :content_type => :json, :accept => :json) return response rescue raise ClientError, $!. end |
#next_job ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rplex/client.rb', line 24 def next_job srv="#{@service}/#{@name}" response=RestClient.get(srv,:accept => :json) unless response.empty? return JSON.parse(response) else return {} end rescue raise ClientError, $!. end |
#remove ⇒ Object
77 78 79 80 81 82 |
# File 'lib/rplex/client.rb', line 77 def remove response=RestClient.delete("#{@service}/configuration/#{@name}") return response rescue raise ClientError, $!. end |
#reset(workers) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rplex/client.rb', line 36 def reset workers if workers && !workers.empty? response=RestClient.post(@service, {"workers"=>workers}, :content_type => :json, :accept => :json) return JSON.parse(response) else return [] end rescue raise ClientError, $!. end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/rplex/client.rb', line 84 def to_s "#{@name} working with #{@service}" end |