def time_of_day(self, recipe, reset): """ Run a daily recipe. """ time_of_day = dates.parse_time_of_day(recipe.time_of_day) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) if reset: pause = min([self.min_pause, pause, self.random_pause()]) log.warning('first run in {1}s: {0}'.format(self.fmt(recipe), round(pause, 2))) time.sleep(pause) runs = 1 while 1: runs += 1 self.cook(recipe) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) log.warning('run #{0} in {2}s of: {1}'.format( runs, self.fmt(recipe), round(pause, 2))) time.sleep(pause)
def time_of_day(self, recipe, reset): """ Run a daily recipe. """ time_of_day = dates.parse_time_of_day(recipe.time_of_day) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) if reset: pause = min([self.min_pause, pause, self.random_pause()]) log.warning('first run in {1}s: {0}' .format(self.fmt(recipe), round(pause, 2))) time.sleep(pause) runs = 1 while 1: runs += 1 self.cook(recipe) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) log.warning('run #{0} in {2}s of: {1}' .format(runs, self.fmt(recipe), round(pause, 2))) time.sleep(pause)
def run_recipe(self, recipe, daily=False): """ Run a scheduled recipe indefinitely """ if daily: time_of_day = dates.parse_time_of_day(recipe.time_of_day) seconds_until = dates.seconds_until(time_of_day) time.sleep(seconds_until) # one day in seconds interval = 24 * 60 * 60 else: interval = copy.copy(recipe.interval) while 1: print 'Running: {} at {}'.format(recipe, dates.now()) api = API(apikey=recipe.user.apikey, org=recipe.org_id) # api.recipes.run(recipe.id) time.sleep(interval)
def run_time_of_day(self, recipe, reset): """ Run a daily recipe. """ time_of_day = dates.parse_time_of_day(recipe.time_of_day) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) if reset: pause = min([self.min_pause, pause, self.random_pause()]) self.log("{} recipe ({} / {}) will run in {} seconds" .format(recipe.schedule_by, recipe.id, recipe.slug, pause)) time.sleep(pause) while 1: self.cook(recipe) # lock to org's timezone. pause = dates.seconds_until(time_of_day, now=recipe.org.now) self.log("{} recipe ({} / {}) will run again in {} seconds" .format(recipe.schedule_by, recipe.id, recipe.slug, pause)) time.sleep(pause)