Class: Ray::Client
- Inherits:
-
Object
- Object
- Ray::Client
- Defined in:
- lib/ray/client.rb
Instance Method Summary collapse
-
#initialize(port = 23517, host = 'localhost') ⇒ Client
constructor
A new instance of Client.
- #lock_exists(lockName) ⇒ Object
- #send(request) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(port = 23517, host = 'localhost') ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/ray/client.rb', line 6 def initialize(port = 23517, host = 'localhost') @port = port @host = host end |
Instance Method Details
#lock_exists(lockName) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ray/client.rb', line 24 def lock_exists(lockName) req = Net::HTTP::Get.new("/locks/#{lockName}", { 'Content-Type' => 'application/json' }) begin response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end rescue StandardError return false end result = JSON.parse(response.body) if (result['stop_execution']) raise new StopExecutionRequested end return result['active'] || false end |
#send(request) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ray/client.rb', line 11 def send(request) req = Net::HTTP::Post.new(uri, { 'Content-Type' => 'application/json' }) req.body = request.to_json begin Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end rescue StandardError # Ignore any errors end end |
#uri ⇒ Object
44 45 46 |
# File 'lib/ray/client.rb', line 44 def uri @uri ||= URI("#{@host}:#{@port}") end |