module TingYun::Agent::InstanceMethods::HandleErrors

Public Instance Methods

handle_delay_restart(error, sec) click to toggle source
# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 58
def handle_delay_restart(error, sec)
  handle_force_restart(error)
  sleep sec
end
handle_force_disconnect(error) click to toggle source
# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 63
def handle_force_disconnect(error)
  TingYun::Agent.logger.warn "Ting Yun forced this agent to disconnect (#{error.message})"
  disconnect
end
handle_force_restart(error) click to toggle source

Handles the case where the server tells us to restart - this clears the data, clears connection attempts, and waits a while to reconnect.

# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 51
def handle_force_restart(error)
  TingYun::Agent.logger.debug error.message
  drop_buffered_data
  @service.force_restart if @service
  @connect_state = :pending
end
handle_license_error(error) click to toggle source

When the server sends us an error with the license key, we want to tell the user that something went wrong, and let them know where to go to get a valid license key

After this runs, it disconnects the agent so that it will no longer try to connect to the server, saving the application and the server load

# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 17
def handle_license_error(error)
  TingYun::Agent.logger.error(\
      error.message, \
      "You need to obtain a valid license key, or to upgrade your account.")
  disconnect
end
handle_other_error(error) click to toggle source

Handles an unknown error in the worker thread by logging it and disconnecting the agent, since we are now in an unknown state.

# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 40
def handle_other_error(error)
  TingYun::Agent.logger.error "Unhandled error in worker thread, disconnecting this agent process:"
  # These errors are fatal (that is, they will prevent the agent from
  # reporting entirely), so we really want backtraces when they happen
  TingYun::Agent.logger.log_exception(:error, error)
  disconnect
end
handle_server_error(error) click to toggle source
# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 68
def handle_server_error(error)
  TingYun::Agent.logger.error(error.message)
  drop_buffered_data
end
handle_unrecoverable_agent_error(error) click to toggle source
# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 24
def handle_unrecoverable_agent_error(error)
  TingYun::Agent.logger.error(error.message)
  disconnect
  shutdown
end
log_error(error) click to toggle source

When we have a problem connecting to the server, we need to tell the user what happened, since this is not an error we can handle gracefully.

# File lib/ting_yun/agent/instance_methods/handle_errors.rb, line 33
def log_error(error)
  TingYun::Agent.logger.error "Error establishing connection with Ting Yun Service at #{service.inspect}:", error
end