Class: Rplex::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rplex/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/rplex/client.rb', line 10

def name
  @name
end

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/rplex/client.rb', line 10

def service
  @service
end

Instance Method Details

#backlogObject



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, $!.message
end

#configurationObject



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, $!.message
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, $!.message
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, $!.message
end

#next_jobObject



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, $!.message
end

#removeObject



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, $!.message
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, $!.message
end

#to_sObject



84
85
86
# File 'lib/rplex/client.rb', line 84

def to_s
  "#{@name} working with #{@service}"
end