def build_job(self): self.job = turtle.Turtle() self.job.runs = [] self.resource = resource.JobResource(self.job) # Freeze the current time to prevent race conditions timeutils.override_current_time(datetime.datetime.now())
def build_job(self): self.job = turtle.Turtle() self.job.runs = [] start_time = datetime.datetime.now() timeutils.override_current_time(start_time) self.resource = resource.JobResource(self.job) self.resource.last_succeed_interval = datetime.timedelta(minutes=1)
def test_correct_time(self): sch = scheduler.DailyScheduler( start_time=datetime.time(hour=0, minute=0), time_zone=pytz.timezone('US/Pacific')) j = self.make_job(sch) now = datetime.datetime(2011, 11, 6, 1, 10, 0) timeutils.override_current_time(now) next_run_time = sch.next_runs(j)[0].run_time assert_equal(next_run_time.hour, 0)
def test_long_jobs_dont_wedge_scheduler(self): # Advance days twice as fast as they are scheduled, demonstrating # that the scheduler will put things in the past if that's where # they belong, and run them as fast as possible last_run = self.scheduler.next_runs(self.job)[0].run_time for i in range(10): next_run = self.scheduler.next_runs(self.job)[0].run_time assert_equal(next_run, last_run + datetime.timedelta(days=1)) self.now += datetime.timedelta(days=2) timeutils.override_current_time(self.now) last_run = next_run
def test_interval_check(self): job_run = turtle.Turtle() job_run.is_success = False self.job.runs.append(job_run) assert not self.resource.is_ready job_run.is_success = True # Should still fail since we don't need to check again assert not self.resource.is_ready # Now push time ahead so we'll re-check next_check = self.resource.next_check_time timeutils.override_current_time(next_check) assert self.resource.is_ready
def hours_to_job_at_datetime(self, sch, *args, **kwargs): """Return the number of hours until the next *two* runs of a job with the given scheduler """ # if you need to print a datetime with tz info, use this: # fmt = '%Y-%m-%d %H:%M:%S %Z%z' # my_datetime.strftime(fmt) j = self.make_job(sch) now = datetime.datetime(*args, **kwargs) timeutils.override_current_time(now) next_run = sch.next_runs(j)[0] t1 = round(next_run.seconds_until_run_time()/60/60, 1) next_run = sch.next_runs(j)[0] t2 = round(next_run.seconds_until_run_time()/60/60, 1) return t1, t2
def hours_to_job_at_datetime(self, job_name, *args, **kwargs): """Return the number of hours until the next *two* runs of a job with the given scheduler """ # if you need to print a datetime with tz info, use this: # fmt = '%Y-%m-%d %H:%M:%S %Z%z' # my_datetime.strftime(fmt) test_dir = tempfile.mkdtemp() self.tmp_dirs.append(test_dir) test_config = config.load_config(StringIO.StringIO(self.config)) my_mcp = mcp.MasterControlProgram(test_dir, 'config') test_config.apply(my_mcp) now = datetime.datetime(*args, **kwargs) timeutils.override_current_time(now) next_run = my_mcp.jobs[job_name].next_runs()[0] t1 = round(next_run.seconds_until_run_time()/60/60, 1) next_run = my_mcp.jobs[job_name].next_runs()[0] t2 = round(next_run.seconds_until_run_time()/60/60, 1) return t1, t2
def set_time(self): self.now = datetime.datetime.now().replace(hour=12, minute=0) timeutils.override_current_time(self.now)
def restore_time(self): timeutils.override_current_time(None)
def class_teardown(self): timeutils.override_current_time(None)
def class_setup(self): timeutils.override_current_time(datetime.datetime.now()) self.now = timeutils.current_time()
def unset_time(self): timeutils.override_current_time(None)
def set_time(self): timeutils.override_current_time(self.today)
def freeze_time(self): timeutils.override_current_time(datetime.datetime.now()) self.now = timeutils.current_time()
def unfreeze_time(self): timeutils.override_current_time(None)