Esempio n. 1
0
 def valid_crontab(self, key, opt):
     """
     Validate a crontab option.
     """
     if opt is None:
         return None
     try:
         dates.cron(opt)
     except Exception as e:
         return RecipeSchemaError(
             "{} should be a 'crontab' field but was passed '{}'. "
             "Here is the error message: {}.".format(key, opt, e.message))
     return opt
Esempio n. 2
0
 def valid_crontab(self, key, opt):
     """
     Validate a crontab option.
     """
     if opt is None:
         return None
     try:
         dates.cron(opt)
     except Exception as e:
         return RecipeSchemaError(
             "{} should be a 'crontab' field but was passed '{}'. "
             "Here is the error message: {}."
             .format(key, opt, e.message))
     return opt
Esempio n. 3
0
    def crontab(self, recipe, reset):
        """
        Run a crontab recipe.
        """
        cron = dates.cron(recipe.crontab)

        # lock to org's timezone.
        pause = cron.next(now=recipe.org.now)

        # reset.
        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 = cron.next(now=recipe.org.now)
            log.warning('run #{0} in {2}s of: {1}'.format(
                runs, self.fmt(recipe), round(pause, 2)))
            time.sleep(pause)
Esempio n. 4
0
    def crontab(self, recipe, reset):
        """
        Run a crontab recipe.
        """
        cron = dates.cron(recipe.crontab)

        # lock to org's timezone.
        pause = cron.next(now=recipe.org.now)

        # reset.
        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 = cron.next(now=recipe.org.now)
            log.warning('run #{0} in {2}s of: {1}'
                        .format(runs, self.fmt(recipe), round(pause, 2)))
            time.sleep(pause)
Esempio n. 5
0
    def run_cron(self, recipe, reset):
        """
        Run a cron recipe.
        """ 
        cron = dates.cron(recipe.crontab)
        
        # lock to org's timezone.
        pause = cron.next(now=recipe.org.now)

        # reset.
        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 = cron.next(now=recipe.org.now)
            self.log("{} recipe ({} / {}) will run again in {} seconds"
                .format(recipe.schedule_by, recipe.id, recipe.slug, pause))
            time.sleep(pause)