Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #19 from fedora-infra/feature/careful-with-the-irc…
Browse files Browse the repository at this point in the history
…-reconnects

Only reconnect to IRC if not shutting down.
  • Loading branch information
ralphbean committed May 14, 2014
2 parents 8843a4c + e9f0caf commit 69b4522
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions fmn/consumer/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@


class BaseBackend(object):
die = False

def __init__(self, config, session, **kwargs):
self.config = config
self.session = session
Expand Down Expand Up @@ -37,3 +39,6 @@ def enable(self, detail_value):

def disable(self, detail_value):
self.preference_for(detail_value).set_enabled(self.session, False)

def stop(self):
self.die = True
14 changes: 12 additions & 2 deletions fmn/consumer/backends/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,21 @@ def __init__(self, parent):
self.parent = parent

def clientConnectionLost(self, connector, reason):
self.parent.log.warning("Lost connection %r, reconnecting." % reason)
self.parent.cleanup_clients(factory=self)

if self.parent.die:
self.parent.log.warning("Lost IRC connection. Shutting down.")
return

self.parent.log.warning("Lost connection %r, reconnecting." % reason)
connector.connect()

def clientConnectionFailed(self, connector, reason):
self.parent.log.error("Could not connect: %r, retry in 60s" % reason)
self.parent.cleanup_clients(factory=self)

if self.parent.die:
self.parent.log.warning("Couldn't connect to IRC. Shutting down.")
return

self.parent.log.error("Could not connect: %r, retry in 60s" % reason)
reactor.callLater(60, connector.connect)
6 changes: 6 additions & 0 deletions fmn/consumer/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ def consume(self, raw_msg):
log.debug(" Queueing msg for digest")
fmn.lib.models.QueuedMessage.enqueue(
self.session, user, context, msg)

def stop(self):
log.info("Cleaning up FMNConsumer.")
for context, backend in self.backends.iteritems():
backend.stop()
super(FMNConsumer, self).stop()

0 comments on commit 69b4522

Please sign in to comment.