Class: Chimp::ChimpDaemonClient
- Inherits:
-
Object
- Object
- Chimp::ChimpDaemonClient
- Defined in:
- lib/right_chimp/daemon/ChimpDaemonClient.rb
Overview
The ChimpDaemonClient contains the code for communicating with the RESTful chimpd Web service
Class Method Summary collapse
- .create_group(host, port, name, type, concurrency) ⇒ Object
-
.quit(host, port) ⇒ Object
quit a remote chimpd.
- .retrieve_group_info(host, port, group_name, status) ⇒ Object
-
.retrieve_job_info(host, port) ⇒ Object
retrieve job info from a remote chimpd.
- .retry_group(host, port, group_name) ⇒ Object
- .set_job_status(host, port, job_id, status) ⇒ Object
-
.submit(host, port, chimp_object) ⇒ Object
Submit a Chimp object to a remote chimpd.
Class Method Details
.create_group(host, port, name, type, concurrency) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 90 def self.create_group(host, port, name, type, concurrency) uri = "http://#{host}:#{port}/group/#{name}/create" payload = { 'type' => type, 'concurrency' => concurrency }.to_yaml response = RestClient.post(uri, payload) return YAML::load(response.body) end |
.quit(host, port) ⇒ Object
quit a remote chimpd
62 63 64 65 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 62 def self.quit(host, port) response = RestClient.post "http://#{host}:#{port}/admin", { 'shutdown' => 'true' }.to_yaml return response.code end |
.retrieve_group_info(host, port, group_name, status) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 77 def self.retrieve_group_info(host, port, group_name, status) uri = "http://#{host}:#{port}/group/#{group_name}/#{status}" response = RestClient.get uri group = YAML::load(response.body) return group end |
.retrieve_job_info(host, port) ⇒ Object
retrieve job info from a remote chimpd
70 71 72 73 74 75 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 70 def self.retrieve_job_info(host, port) uri = "http://#{host}:#{port}/job/0" response = RestClient.get uri jobs = YAML::load(response.body) return jobs end |
.retry_group(host, port, group_name) ⇒ Object
97 98 99 100 101 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 97 def self.retry_group(host, port, group_name) uri = "http://#{host}:#{port}/group/#{group_name}/retry" response = RestClient.post(uri, {}) return YAML::load(response.body) end |
.set_job_status(host, port, job_id, status) ⇒ Object
84 85 86 87 88 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 84 def self.set_job_status(host, port, job_id, status) uri = "http://#{host}:#{port}/job/#{job_id}/update" response = RestClient.post uri, { :status => status} return YAML::load(response.body) end |
.submit(host, port, chimp_object) ⇒ Object
Submit a Chimp object to a remote chimpd
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/right_chimp/daemon/ChimpDaemonClient.rb', line 10 def self.submit(host, port, chimp_object) uri = "http://#{host}:#{port}/job/process" attempts = 3 begin response = RestClient.post uri, chimp_object.to_yaml if response.code > 199 and response.code < 300 id = YAML::load(response.body)['id'] return true else $stderr.puts "WARNING: error submitting to chimpd! response code: #{reponse.code}" return false end rescue RestClient::RequestTimeout => ex $stderr.puts "WARNING: Request timeout talking to chimpd for job #{chimp_object.script}: #{ex.} (#{ex.http_code})" attempts -= 1 sleep 5 and retry if attempts > 0 return false rescue RestClient::InternalServerError => ex $stderr.puts "WARNING: Error submitting job to chimpd: #{}, retrying..." attempts -= 1 sleep 5 and retry if attempts > 0 return false rescue Errno::ECONNRESET => ex $stderr.puts "WARNING: Connection reset by peer, retrying..." attempts -= 1 sleep 5 and retry if attempts > 0 return false rescue Errno::EPIPE => ex $stderr.puts "WARNING: broken pipe, retrying..." attempts -= 1 sleep 5 and retry if attempts > 0 return false rescue Errno::ECONNREFUSED => ex $stderr.puts "ERROR: connection refused, aborting" return false rescue RestClient::Exception => ex $stderr.puts "ERROR: Error submitting job to chimpd #{chimp_object.script}: #{ex.}" return false end end |