mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 17:44:09 +01:00
Scheduler: handle event persistence on plugin reload.
Write data to disk on unload; populate events dict with events which are still scheduled on reload.
This commit is contained in:
parent
42efc79ef1
commit
f6e3698c24
@ -66,18 +66,26 @@ class Scheduler(callbacks.Plugin):
|
|||||||
except IOError, e:
|
except IOError, e:
|
||||||
self.log.debug('Unable to open pickle file: %s', e)
|
self.log.debug('Unable to open pickle file: %s', e)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
for name, event in eventdict.iteritems():
|
for name, event in eventdict.iteritems():
|
||||||
ircobj = callbacks.ReplyIrcProxy(irc, event['msg'])
|
ircobj = callbacks.ReplyIrcProxy(irc, event['msg'])
|
||||||
|
try:
|
||||||
if event['type'] == 'single': # non-repeating event
|
if event['type'] == 'single': # non-repeating event
|
||||||
|
n = None
|
||||||
|
if schedule.schedule.counter > int(name):
|
||||||
|
# counter not reset, we're probably reloading the plugin
|
||||||
|
# though we'll never know for sure, because other
|
||||||
|
# plugins can schedule stuff, too.
|
||||||
|
n = int(name)
|
||||||
self._add(ircobj, event['msg'],
|
self._add(ircobj, event['msg'],
|
||||||
event['time'], event['command'])
|
event['time'], event['command'], n)
|
||||||
elif event['type'] == 'repeat': # repeating event
|
elif event['type'] == 'repeat': # repeating event
|
||||||
self._repeat(ircobj, event['msg'], name,
|
self._repeat(ircobj, event['msg'], name,
|
||||||
event['time'], event['command'])
|
event['time'], event['command'])
|
||||||
except AssertionError, e:
|
except AssertionError, e:
|
||||||
if str(e) == 'An event with the same name has already been scheduled.':
|
if str(e) == 'An event with the same name has already been scheduled.':
|
||||||
pass # we must be reloading the plugin
|
# we must be reloading the plugin, event is still scheduled
|
||||||
|
self.log.info('Event %s already exists, adding to dict.' % (name,))
|
||||||
|
self.events[name] = event
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@ -95,6 +103,7 @@ class Scheduler(callbacks.Plugin):
|
|||||||
self.log.warning('File error: %s', e)
|
self.log.warning('File error: %s', e)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
|
self._flush()
|
||||||
world.flushers.remove(self._flush)
|
world.flushers.remove(self._flush)
|
||||||
self.__parent.die()
|
self.__parent.die()
|
||||||
|
|
||||||
@ -107,9 +116,9 @@ class Scheduler(callbacks.Plugin):
|
|||||||
self.Proxy(irc.irc, msg, tokens)
|
self.Proxy(irc.irc, msg, tokens)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def _add(self, irc, msg, t, command):
|
def _add(self, irc, msg, t, command, name=None):
|
||||||
f = self._makeCommandFunction(irc, msg, command)
|
f = self._makeCommandFunction(irc, msg, command)
|
||||||
id = schedule.addEvent(f, t)
|
id = schedule.addEvent(f, t, name)
|
||||||
f.eventId = id
|
f.eventId = id
|
||||||
self.events[str(id)] = {'command':command,
|
self.events[str(id)] = {'command':command,
|
||||||
'msg':msg,
|
'msg':msg,
|
||||||
|
Loading…
Reference in New Issue
Block a user