[storm] reconnection
olivetree123
olivetree123 at 126.com
Mon Nov 23 10:57:24 UTC 2015
when disconnected by mysql, it will be error all the time......
I hope it will be reconnected when mysql has gone away.
Also,I hope you will put code on github, I love storm very much,I want to contribute to it.
My code of reconnection :
def _check_and_reconnect(self):
if not isinstance(self._database,storm.databases.mysql.MySQL):
return 0
try:
self._raw_connection.ping()
except Exception,e:
try:
print '--disconnected--'
self._raw_connection = self._database.raw_connect()
print '--reconnected---'
except Exception,e:
print '--reconnect failed--'
return 0
self._state = STATE_CONNECTED
return 1
def _ensure_connected(self):
"""Ensure that we are connected to the database.
If the connection is marked as dead, or if we can't reconnect,
then raise DisconnectionError.
"""
if self._blocked:
raise ConnectionBlockedError("Access to connection is blocked")
self._check_and_reconnect()
if self._state == STATE_CONNECTED:
return
elif self._state == STATE_DISCONNECTED:
raise DisconnectionError("Already disconnected")
elif self._state == STATE_RECONNECT:
try:
self._raw_connection = self._database.raw_connect()
except DatabaseError, exc:
self._state = STATE_DISCONNECTED
self._raw_connection = None
raise DisconnectionError(str(exc))
else:
self._state = STATE_CONNECTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/storm/attachments/20151123/af084a93/attachment.html>
More information about the storm
mailing list