mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Scheduler: Make @list show period and time before next run.
This commit is contained in:
parent
a58c994954
commit
d627ba7683
@ -57,9 +57,9 @@ class Scheduler(callbacks.Plugin):
|
|||||||
self._restoreEvents(irc)
|
self._restoreEvents(irc)
|
||||||
world.flushers.append(self._flush)
|
world.flushers.append(self._flush)
|
||||||
|
|
||||||
def _getNextRunIn(self, first_run, now, period):
|
def _getNextRunIn(self, first_run, now, period, not_right_now=False):
|
||||||
next_run_in = period - ((now - first_run) % period)
|
next_run_in = period - ((now - first_run) % period)
|
||||||
if next_run_in < 5:
|
if not_right_now and next_run_in < 5:
|
||||||
# don't run immediatly, it might overwhelm the bot on
|
# don't run immediatly, it might overwhelm the bot on
|
||||||
# startup.
|
# startup.
|
||||||
next_run_in += period
|
next_run_in += period
|
||||||
@ -102,7 +102,7 @@ class Scheduler(callbacks.Plugin):
|
|||||||
# is 24hours, we want to keep running the command at the
|
# is 24hours, we want to keep running the command at the
|
||||||
# same time of day.
|
# same time of day.
|
||||||
next_run_in = self._getNextRunIn(
|
next_run_in = self._getNextRunIn(
|
||||||
first_run, now, event['time'])
|
first_run, now, event['time'], not_right_now=True)
|
||||||
|
|
||||||
self._repeat(ircobj, event['msg'], name,
|
self._repeat(ircobj, event['msg'], name,
|
||||||
event['time'], event['command'], first_run, next_run_in)
|
event['time'], event['command'], first_run, next_run_in)
|
||||||
@ -235,9 +235,18 @@ class Scheduler(callbacks.Plugin):
|
|||||||
L = list(self.events.items())
|
L = list(self.events.items())
|
||||||
if L:
|
if L:
|
||||||
L.sort()
|
L.sort()
|
||||||
for (i, (name, command)) in enumerate(L):
|
replies = []
|
||||||
L[i] = format('%s: %q', name, command['command'])
|
now = time.time()
|
||||||
irc.reply(format('%L', L))
|
for (i, (name, event)) in enumerate(L):
|
||||||
|
if event['type'] == 'single':
|
||||||
|
replies.append(format('%s (in %T): %q', name,
|
||||||
|
event['time'] - now, event['command']))
|
||||||
|
else:
|
||||||
|
next_run_in = self._getNextRunIn(
|
||||||
|
event['first_run'], now, event['time'])
|
||||||
|
replies.append(format('%s (every %T, next run in %T): %q',
|
||||||
|
name, event['time'], next_run_in, event['command']))
|
||||||
|
irc.reply(format('%L', replies))
|
||||||
else:
|
else:
|
||||||
irc.reply(_('There are currently no scheduled commands.'))
|
irc.reply(_('There are currently no scheduled commands.'))
|
||||||
list = wrap(list)
|
list = wrap(list)
|
||||||
|
@ -41,7 +41,9 @@ class SchedulerTestCase(ChannelPluginTestCase):
|
|||||||
def testAddRemove(self):
|
def testAddRemove(self):
|
||||||
self.assertRegexp('scheduler list', 'no.*commands')
|
self.assertRegexp('scheduler list', 'no.*commands')
|
||||||
m = self.assertNotError('scheduler add 5 echo testAddRemove')
|
m = self.assertNotError('scheduler add 5 echo testAddRemove')
|
||||||
self.assertRegexp('scheduler list', 'echo testAddRemove')
|
self.assertResponse(
|
||||||
|
'scheduler list',
|
||||||
|
'1 (in 4 seconds): "echo testAddRemove"')
|
||||||
timeFastForward(2)
|
timeFastForward(2)
|
||||||
self.assertNoResponse(' ', timeout=1)
|
self.assertNoResponse(' ', timeout=1)
|
||||||
timeFastForward(2)
|
timeFastForward(2)
|
||||||
@ -77,7 +79,10 @@ class SchedulerTestCase(ChannelPluginTestCase):
|
|||||||
'testRepeat')
|
'testRepeat')
|
||||||
timeFastForward(5)
|
timeFastForward(5)
|
||||||
self.assertResponse(' ', 'testRepeat')
|
self.assertResponse(' ', 'testRepeat')
|
||||||
self.assertResponse('scheduler list', 'repeater: "echo testRepeat"')
|
self.assertResponse(
|
||||||
|
'scheduler list',
|
||||||
|
'repeater (every 5 seconds, next run in 4 seconds): '
|
||||||
|
'"echo testRepeat"')
|
||||||
timeFastForward(3)
|
timeFastForward(3)
|
||||||
self.assertNoResponse(' ', timeout=1)
|
self.assertNoResponse(' ', timeout=1)
|
||||||
timeFastForward(2)
|
timeFastForward(2)
|
||||||
|
Loading…
Reference in New Issue
Block a user