Module: TingYun::Agent::InstanceMethods::HandleErrors
- Included in:
- Connect
- Defined in:
- lib/ting_yun/agent/instance_methods/handle_errors.rb
Instance Method Summary collapse
- #handle_delay_restart(error, sec) ⇒ Object
- #handle_force_disconnect(error) ⇒ Object
-
#handle_force_restart(error) ⇒ Object
Handles the case where the server tells us to restart - this clears the data, clears connection attempts, and waits a while to reconnect.
-
#handle_license_error(error) ⇒ Object
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.
-
#handle_other_error(error) ⇒ Object
Handles an unknown error in the worker thread by logging it and disconnecting the agent, since we are now in an unknown state.
- #handle_server_error(error) ⇒ Object
- #handle_unrecoverable_agent_error(error) ⇒ Object
-
#log_error(error) ⇒ Object
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.
Instance Method Details
#handle_delay_restart(error, sec) ⇒ Object
58 59 60 61 |
# 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) ⇒ Object
63 64 65 66 |
# 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.})" disconnect end |
#handle_force_restart(error) ⇒ Object
Handles the case where the server tells us to restart - this clears the data, clears connection attempts, and waits a while to reconnect.
51 52 53 54 55 56 |
# File 'lib/ting_yun/agent/instance_methods/handle_errors.rb', line 51 def handle_force_restart(error) TingYun::Agent.logger.debug error. drop_buffered_data @service.force_restart if @service @connect_state = :pending end |
#handle_license_error(error) ⇒ Object
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
17 18 19 20 21 22 |
# File 'lib/ting_yun/agent/instance_methods/handle_errors.rb', line 17 def handle_license_error(error) TingYun::Agent.logger.error(\ error., \ "You need to obtain a valid license key, or to upgrade your account.") disconnect end |
#handle_other_error(error) ⇒ Object
Handles an unknown error in the worker thread by logging it and disconnecting the agent, since we are now in an unknown state.
40 41 42 43 44 45 46 |
# 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) ⇒ Object
68 69 70 71 |
# File 'lib/ting_yun/agent/instance_methods/handle_errors.rb', line 68 def handle_server_error(error) TingYun::Agent.logger.error(error.) drop_buffered_data end |
#handle_unrecoverable_agent_error(error) ⇒ Object
24 25 26 27 28 |
# File 'lib/ting_yun/agent/instance_methods/handle_errors.rb', line 24 def handle_unrecoverable_agent_error(error) TingYun::Agent.logger.error(error.) disconnect shutdown end |
#log_error(error) ⇒ Object
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.
33 34 35 |
# 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 |