예제 #1
0
 def get(self, now=None):
     """Shows template displaying the configured cron jobs."""
     if not now:
         now = datetime.datetime.now()
     values = {'request': self.request}
     cron_info = _ParseCronYaml()
     values['cronjobs'] = []
     values['now'] = str(now)
     if cron_info and cron_info.cron:
         for entry in cron_info.cron:
             job = {}
             values['cronjobs'].append(job)
             if entry.description:
                 job['description'] = entry.description
             else:
                 job['description'] = '(no description)'
             if entry.timezone:
                 job['timezone'] = entry.timezone
             job['url'] = entry.url
             job['schedule'] = entry.schedule
             schedule = groctimespecification.GrocTimeSpecification(
                 entry.schedule)
             matches = schedule.GetMatches(now, 3)
             job['times'] = []
             for match in matches:
                 job['times'].append({
                     'runtime':
                     match.strftime("%Y-%m-%d %H:%M:%SZ"),
                     'difference':
                     str(match - now)
                 })
     self.generate('cron.html', values)
예제 #2
0
 def Validate(self, value, key=None):
   """Validates a schedule."""
   if value is None:
     raise validation.MissingAttribute('schedule must be specified')
   if not isinstance(value, basestring):
     raise TypeError('schedule must be a string, not \'%r\''%type(value))
   try:
     groctimespecification.GrocTimeSpecification(value)
   except groc.GrocException, e:
     raise validation.ValidationError('schedule \'%s\' failed to parse: %s'%(
         value, e.args[0]))
예제 #3
0
    def _ValidateCronEntry(self, cron):

        if not cron.url:
            return 'No URL for <cron> entry'
        if not cron.schedule:
            return "No schedule provided for <cron> entry with URL '%s'" % cron.url
        try:
            groctimespecification.GrocTimeSpecification(cron.schedule)
        except groc.GrocException:
            return ("Text '%s' in <schedule> node failed to parse,"
                    ' for <cron> entry with url %s.' %
                    (cron.schedule, cron.url))
예제 #4
0
 def _get_cron_jobs(self):
   cron_info = self._parse_cron_yaml()
   if not cron_info or not cron_info.cron:
     return []
   jobs = []
   for entry in cron_info.cron:
     job = entry.ToDict()
     if not entry.timezone or pytz:
       now = datetime.datetime.utcnow()
       schedule = groctimespecification.GrocTimeSpecification(
           entry.schedule, entry.timezone)
       matches = schedule.GetMatches(now, 3)
       job['times'] = []
       for match in matches:
         job['times'].append(
             {'runtime': match.strftime('%Y-%m-%d %H:%M:%SZ'),
              'difference': str(match - now)})
     jobs.append(job)
   return jobs