lib/adhearsion/voip/asterisk/manager_interface.rb in adhearsion-0.8.5 vs lib/adhearsion/voip/asterisk/manager_interface.rb in adhearsion-0.8.6
- old
+ new
@@ -31,10 +31,12 @@
CAUSAL_EVENT_NAMES = %w[queuestatus sippeers iaxpeers parkedcalls
dahdishowchannels coreshowchannels dbget
status konferencelist] unless defined? CAUSAL_EVENT_NAMES
+ RETRY_SLEEP = 5
+
class << self
def connect(*args)
returning new(*args) do |connection|
connection.connect!
@@ -260,15 +262,15 @@
end
def clear_actions_connection
stop_actions_writer_loop
clear_actions_connection_resources
- disconnect_actions_connection
+ disconnect_actions_connection if @actions_state.equal? :connected
end
def clear_events_connection
- disconnect_events_connection
+ disconnect_events_connection if @events_state.equal? :connected
end
def disconnect!
clear_actions_connection
clear_events_connection
@@ -541,10 +543,14 @@
handler.receive_data { |data| @actions_lexer << data }
handler.connected { actions_connection_established }
handler.disconnected { actions_connection_disconnected }
end
login_actions
+ rescue Errno::ECONNREFUSED => e
+ ahn_log.ami.warn "ACTIONS thread connection refused! Retrying in #{RETRY_SLEEP} seconds..."
+ sleep RETRY_SLEEP
+ retry
end
def disconnect_actions_connection
# Clean up the EventSocket we may have
if @actions_connection
@@ -567,9 +573,13 @@
handler.connected { events_connection_established }
handler.disconnected { events_connection_disconnected }
end
login_events
ahn_log.ami "Successful AMI events-only connection into #{@username}@#{@host}"
+ rescue Errno::ECONNREFUSED => e
+ ahn_log.ami.warn "EVENTS thread connection refused! Retrying in #{RETRY_SLEEP} seconds..."
+ sleep RETRY_SLEEP
+ retry
end
def login_actions
action = send_action_asynchronously "Login", "Username" => @username, "Secret" => @password, "Events" => "Off"
response = action.response