class Foodtaster::Client

Constants

MAX_ATTEMPTS

Public Class Methods

connect(drb_port, server_process = nil) click to toggle source
# File lib/foodtaster/client.rb, line 8
def self.connect(drb_port, server_process = nil)
  attempt_index = 1
  begin
    sleep 0.2
    client = Foodtaster::Client.new(drb_port)
  rescue DRb::DRbConnError => e
    Foodtaster.logger.debug "DRb connection failed (attempt #{attempt_index}/#{MAX_ATTEMPTS}): #{e.message}"
    attempt_index += 1
    retry if attempt_index <= MAX_ATTEMPTS && (server_process.nil? || server_process.alive?)
  end

  if client
    Foodtaster.logger.debug "DRb connection established"
  else
    Foodtaster.logger.debug "Can't connect to Foodtaster DRb Server"
  end

  client
end
new(drb_port) click to toggle source
# File lib/foodtaster/client.rb, line 46
def initialize(drb_port)
  # start local service to be able to redirect stdout & stderr
  # to client
  DRb.start_service("druby://localhost:0")
  @v = DRbObject.new_with_uri("druby://localhost:#{drb_port}")

  init
end

Private Instance Methods

check_version() click to toggle source
# File lib/foodtaster/client.rb, line 65
     def check_version
       server_version = @v.version

       if server_version != Foodtaster::VERSION
         Foodtaster.logger.warn <<-TEXT
Warning: Foodtaster DRb Server version doesn't match Foodtaster Gem version.

DRb Server version: #{server_version}
Foodtaster Gem version: #{Foodtaster::VERSION}
         TEXT
       end
     end
init() click to toggle source
# File lib/foodtaster/client.rb, line 57
def init
  $stdout.extend DRbUndumped
  $stderr.extend DRbUndumped

  @v.redirect_stdstreams($stdout, $stderr)
  check_version
end