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

Commit

Permalink
Merge pull request #10 from fedora-infra/feature/retry
Browse files Browse the repository at this point in the history
Try again later when we're unable to wrap meetbot.
  • Loading branch information
ralphbean committed Jun 29, 2015
2 parents f167deb + e0d52bc commit 5ebe7f7
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions supybot-fedmsg/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# A flag placed on wrapped methods to note we have already wrapped them once.
SENTINEL = '_sentinel_flag'

# When we start up, we try to wrap meetbot. But if it's not there, we die and
# create a new thread that wakes up in 60s and tries again.
INTERVAL = 60


def already_wrapped(method):
""" Return true if it looks like we have already wrapped a target. """
Expand Down Expand Up @@ -40,7 +44,7 @@ def __init__(self, irc):
fedmsg.init(name="supybot." + hostname)

# Launch in a thread to duckpunch *after* the other plugins
# have been setup.
# have been set up.
thread = Injector()
thread.start()

Expand All @@ -52,29 +56,24 @@ class Injector(threading.Thread):
before we try.
"""

def run(self):
# Sleep 2 seconds
time.sleep(2)

# Then, do our thing.
self._duckpunch_meetbot()

# TODO -- _duckpunch_announce()


def _duckpunch_meetbot(shmelf):
def run(shmelf):
""" Replace some of meetbot's methods with our own which simply call
meetbot's original method, and then emit a fedmsg message before
returning.
"""

time.sleep(INTERVAL)

try:
import sys
target_cls = sys.modules['MeetBot.meeting'].Meeting
except KeyError:
raise ValueError(
"MeetBot not yet enabled. Try Fedmsg again later."
)
# Start another thread to finish our work later.
another_thread = Injector()
another_thread.start()
print "MeetBot not yet enabled."
print " Will try to wrap fedmsg again in %is" % INTERVAL
return # Bail out early.

tap_points = {
'do_startmeeting': 'meeting.start',
Expand Down Expand Up @@ -138,9 +137,5 @@ def wrapper(self, *args, **kw):
new_method = wrapper_factory(topic=topic)
setattr(target_cls, target_method, new_method)

def _duckpunch_announce(shmelf):
""" Instrument the announce plugin to emit messages. """
raise NotImplementedError


Class = Fedmsg

0 comments on commit 5ebe7f7

Please sign in to comment.