def makeJob(self, msg, start, volume=None): """ Builds a scheduler Job object to annouce an mp3 at a certain time. """ announce = Sound(msg) announce.buildMp3() if volume: announce.setVolume(volume) Job = schedule.Job(interval=1, scheduler=self._scheduler) Job.unit = 'days' str_time = "{}:{}".format(start.hour, start.minute) print "Starting warning at: ", str_time Job.at(str_time).do(announce)
def start(): # Keep the log file FD open when daemonizing keep_fds = [handler.stream.fileno() for handler in logger.handlers] # Set jobs scheduler = schedule.default_scheduler job = schedule.Job(current_app.config["DB_BACKUP_INTERVAL"], scheduler) getattr(job, current_app.config["DB_BACKUP_TIME_UNIT"]).do(backup_db_job) # schedule.every().day.do(backup_db_job) daemon = daemonize.Daemonize(app='webcomicsd', pid=PID_FILE, keep_fds=keep_fds, action=main) daemon.start()
def test_time_units(self): assert every().seconds.unit == "seconds" assert every().minutes.unit == "minutes" assert every().hours.unit == "hours" assert every().days.unit == "days" assert every().weeks.unit == "weeks" job_instance = schedule.Job(interval=2) # without a context manager, it incorrectly raises an error because # it is not callable with self.assertRaises(IntervalError): job_instance.minute with self.assertRaises(IntervalError): job_instance.hour with self.assertRaises(IntervalError): job_instance.day with self.assertRaises(IntervalError): job_instance.week with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.monday\(\) jobs is only allowed for weekly jobs\. " r"Using \.monday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.monday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.tuesday\(\) jobs is only allowed for weekly jobs\. " r"Using \.tuesday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.tuesday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.wednesday\(\) jobs is only allowed for weekly jobs\. " r"Using \.wednesday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.wednesday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.thursday\(\) jobs is only allowed for weekly jobs\. " r"Using \.thursday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.thursday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.friday\(\) jobs is only allowed for weekly jobs\. " r"Using \.friday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.friday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.saturday\(\) jobs is only allowed for weekly jobs\. " r"Using \.saturday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.saturday with self.assertRaisesRegex( IntervalError, ( r"Scheduling \.sunday\(\) jobs is only allowed for weekly jobs\. " r"Using \.sunday\(\) on a job scheduled to run every 2 or more " r"weeks is not supported\." ), ): job_instance.sunday # test an invalid unit job_instance.unit = "foo" self.assertRaises(ScheduleValueError, job_instance.at, "1:0:0") self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test start day exists but unit is not 'weeks' job_instance.unit = "days" job_instance.start_day = 1 self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test weeks with an invalid start day job_instance.unit = "weeks" job_instance.start_day = "bar" self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test a valid unit with invalid hours/minutes/seconds job_instance.unit = "days" self.assertRaises(ScheduleValueError, job_instance.at, "25:00:00") self.assertRaises(ScheduleValueError, job_instance.at, "00:61:00") self.assertRaises(ScheduleValueError, job_instance.at, "00:00:61") # test invalid time format self.assertRaises(ScheduleValueError, job_instance.at, "25:0:0") self.assertRaises(ScheduleValueError, job_instance.at, "0:61:0") self.assertRaises(ScheduleValueError, job_instance.at, "0:0:61") # test (very specific) seconds with unspecified start_day job_instance.unit = "seconds" job_instance.at_time = datetime.datetime.now() job_instance.start_day = None self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test self.latest >= self.interval job_instance.latest = 1 self.assertRaises(ScheduleError, job_instance._schedule_next_run) job_instance.latest = 3 self.assertRaises(ScheduleError, job_instance._schedule_next_run)
def test_time_units(self): assert every().seconds.unit == 'seconds' assert every().minutes.unit == 'minutes' assert every().hours.unit == 'hours' assert every().days.unit == 'days' assert every().weeks.unit == 'weeks' job_instance = schedule.Job(interval=2) # without a context manager, it incorrectly raises an error because # it is not callable with self.assertRaises(IntervalError): job_instance.minute with self.assertRaises(IntervalError): job_instance.hour with self.assertRaises(IntervalError): job_instance.day with self.assertRaises(IntervalError): job_instance.week with self.assertRaises(IntervalError): job_instance.monday with self.assertRaises(IntervalError): job_instance.tuesday with self.assertRaises(IntervalError): job_instance.wednesday with self.assertRaises(IntervalError): job_instance.thursday with self.assertRaises(IntervalError): job_instance.friday with self.assertRaises(IntervalError): job_instance.saturday with self.assertRaises(IntervalError): job_instance.sunday # test an invalid unit job_instance.unit = "foo" self.assertRaises(ScheduleValueError, job_instance.at, "1:0:0") self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test start day exists but unit is not 'weeks' job_instance.unit = "days" job_instance.start_day = 1 self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test weeks with an invalid start day job_instance.unit = "weeks" job_instance.start_day = "bar" self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test a valid unit with invalid hours/minutes/seconds job_instance.unit = "days" self.assertRaises(ScheduleValueError, job_instance.at, "25:00:00") self.assertRaises(ScheduleValueError, job_instance.at, "00:61:00") self.assertRaises(ScheduleValueError, job_instance.at, "00:00:61") # test invalid time format self.assertRaises(ScheduleValueError, job_instance.at, "25:0:0") self.assertRaises(ScheduleValueError, job_instance.at, "0:61:0") self.assertRaises(ScheduleValueError, job_instance.at, "0:0:61") # test (very specific) seconds with unspecified start_day job_instance.unit = "seconds" job_instance.at_time = datetime.datetime.now() job_instance.start_day = None self.assertRaises(ScheduleValueError, job_instance._schedule_next_run) # test self.latest >= self.interval job_instance.latest = 1 self.assertRaises(ScheduleError, job_instance._schedule_next_run) job_instance.latest = 3 self.assertRaises(ScheduleError, job_instance._schedule_next_run)
def collectEventsJob(self): ##todo::run every week day Job = schedule.Job(interval=1, scheduler=self.getScheduler()) Job.unit = 'days' Job.at("06:45").do(self.morningRoutine)