mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-25 20:41:18 -05:00
Merge 466941cf3f9d12200b24c99ce2ceb93f7985c45e into c81ff286975701ae78246cd8f24284ca3aeac86d
This commit is contained in:
commit
3d0733a71d
@ -33,6 +33,7 @@ import os
|
||||
import math
|
||||
import shutil
|
||||
import tempfile
|
||||
import datetime
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
@ -272,6 +273,36 @@ class Scheduler(callbacks.Plugin):
|
||||
getopts({'delay': 'positiveInt'}),
|
||||
'nonInt', 'positiveInt', 'text'])
|
||||
|
||||
@internationalizeDocstring
|
||||
def daily(self, irc, msg, args, name, time_of_day, command):
|
||||
""" <name> <time_of_day> <command>
|
||||
|
||||
Schedules a command <command> to run daily at a given
|
||||
time <time_of_day>. The format of <time_of_day> is HH:MM:SS
|
||||
"""
|
||||
name = name.lower()
|
||||
if name in self.events:
|
||||
irc.error(_('There is already an event with that name, please '
|
||||
'choose another name.'), Raise=True)
|
||||
epoch = int(time.time())
|
||||
seconds_until_next_run = 0
|
||||
while True:
|
||||
dt = datetime.datetime.fromtimestamp(epoch + seconds_until_next_run)
|
||||
try:
|
||||
hours, minutes, seconds = map(int, time_of_day.split(":"))
|
||||
except ValueError:
|
||||
irc.error(_('Unable to parse time_of_day'), Raise=True)
|
||||
if dt.hour == hours and dt.minute == minutes and dt.second == seconds:
|
||||
break
|
||||
seconds_until_next_run += 1
|
||||
|
||||
self._repeat(irc.network, msg, name, 60 * 60 * 24, command,
|
||||
epoch + seconds_until_next_run, seconds_until_next_run)
|
||||
# Reply status since the command is run at a later time
|
||||
irc.replySuccess()
|
||||
|
||||
daily = wrap(daily, ['nonInt', 'nonInt', 'text'])
|
||||
|
||||
@internationalizeDocstring
|
||||
def list(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
@ -29,6 +29,8 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
###
|
||||
|
||||
import datetime
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
import supybot.schedule as schedule
|
||||
@ -107,6 +109,29 @@ class SchedulerTestCase(ChannelPluginTestCase):
|
||||
timeFastForward(5)
|
||||
self.assertNoResponse(' ', timeout=1)
|
||||
|
||||
# This test fails if run later
|
||||
def test01Daily(self):
|
||||
self.assertRegexp('scheduler list', 'no.*commands')
|
||||
dt = datetime.datetime.now() + datetime.timedelta(seconds=10)
|
||||
event_time = "{}:{}:{}".format(dt.hour, dt.minute, dt.second)
|
||||
|
||||
self.assertRegexp('scheduler daily dailytask {} echo testDaily'.format(event_time),
|
||||
'The operation succeeded.')
|
||||
|
||||
self.assertNoResponse(' ', timeout=1)
|
||||
timeFastForward(10)
|
||||
self.assertResponse(' ', 'testDaily')
|
||||
|
||||
timeFastForward(60 * 60 * 24 - 2) # Two seconds before event time on the following day
|
||||
self.assertNoResponse(' ', timeout=1)
|
||||
timeFastForward(2)
|
||||
self.assertResponse(' ', 'testDaily')
|
||||
|
||||
timeFastForward(60 * 60 * 12) # Sanity checking that future events also work
|
||||
self.assertNoResponse(' ', timeout=1)
|
||||
timeFastForward(60 * 60 * 12)
|
||||
self.assertResponse(' ', 'testDaily')
|
||||
|
||||
def testRepeatDelay(self):
|
||||
self.assertNoResponse(
|
||||
'scheduler repeat --delay 5 repeater 20 echo testRepeat',
|
||||
|
Loading…
x
Reference in New Issue
Block a user