예제 #1
0
 def list_jobs(self, stream=None):
     if not stream:
         stream = sys.stdout
     _fmt = '%Y-%m-%d %H:%M:%S'
     _now = utc_now()
     PAD = 15
     for class_name, job_class in self.config.crontabber.jobs.class_list:
         class_config = self.config.crontabber['class-%s' % class_name]
         freq = class_config.frequency
         if class_config.time:
             freq += ' @ %s' % class_config.time
         class_name = job_class.__module__ + '.' + job_class.__name__
         stream.write('=== JOB %s\n' % ('=' * 72))
         stream.write('%s%s\n' % ('Class:'.ljust(PAD), class_name))
         stream.write('%s%s\n' %
                      ('App name:'.ljust(PAD), job_class.app_name))
         stream.write('%s%s\n' % ('Frequency:'.ljust(PAD), freq))
         try:
             info = self.job_state_database[job_class.app_name]
         except KeyError:
             stream.write('*NO PREVIOUS RUN INFO*')
             continue
         if info.get('ongoing'):
             stream.write('Ongoing now! '.ljust(PAD))
             stream.write('Started %s ago\n' %
                          timesince(_now, info.get('ongoing')))
         stream.write('Last run:'.ljust(PAD))
         if info['last_run']:
             stream.write(info['last_run'].strftime(_fmt).ljust(20))
             stream.write('(%s ago)\n' % timesince(info['last_run'], _now))
         else:
             stream.write('none\n')
         stream.write('Last success:'.ljust(PAD))
         if info.get('last_success'):
             stream.write(info['last_success'].strftime(_fmt).ljust(20))
             stream.write('(%s ago)\n' %
                          timesince(info['last_success'], _now))
         else:
             stream.write('no previous successful run\n')
         stream.write('Next run:'.ljust(PAD))
         if info['next_run']:
             stream.write(info['next_run'].strftime(_fmt).ljust(20))
             if _now > info['next_run']:
                 stream.write(' (was %s ago)\n' %
                              timesince(info['next_run'], _now))
             else:
                 stream.write(' (in %s)\n' %
                              timesince(_now, info['next_run']))
         else:
             stream.write('none\n')
         if info.get('last_error') not in (None, '{}'):
             last_error = json.loads(info['last_error'])
             stream.write('Error!!'.ljust(PAD) +
                          ' (%s times)\n' % info['error_count'])
             stream.write('Traceback (most recent call last):')
             stream.write('%s %s: %s\n' %
                          (last_error['traceback'], last_error['type'],
                           last_error['value']))
         stream.write('\n')
예제 #2
0
 def list_jobs(self, stream=None):
     if not stream:
         stream = sys.stdout
     _fmt = '%Y-%m-%d %H:%M:%S'
     _now = utc_now()
     PAD = 15
     for class_name, job_class in self.config.crontabber.jobs.class_list:
         class_config = self.config.crontabber['class-%s' % class_name]
         freq = class_config.frequency
         if class_config.time:
             freq += ' @ %s' % class_config.time
         class_name = job_class.__module__ + '.' + job_class.__name__
         stream.write('=== JOB %s\n' % ('=' * 72))
         stream.write('%s%s\n' % ('Class:'.ljust(PAD), class_name))
         stream.write('%s%s\n' % ('App name:'.ljust(PAD), job_class.app_name))
         stream.write('%s%s\n' % ('Frequency:'.ljust(PAD), freq))
         try:
             info = self.job_state_database[job_class.app_name]
         except KeyError:
             stream.write('*NO PREVIOUS RUN INFO*')
             continue
         if info.get('ongoing'):
             stream.write('Ongoing now! '.ljust(PAD))
             stream.write('Started %s ago\n' % timesince(_now, info.get('ongoing')))
         stream.write('Last run:'.ljust(PAD))
         if info['last_run']:
             stream.write(info['last_run'].strftime(_fmt).ljust(20))
             stream.write('(%s ago)\n' % timesince(info['last_run'], _now))
         else:
             stream.write('none\n')
         stream.write('Last success:'.ljust(PAD))
         if info.get('last_success'):
             stream.write(info['last_success'].strftime(_fmt).ljust(20))
             stream.write('(%s ago)\n' % timesince(info['last_success'], _now))
         else:
             stream.write('no previous successful run\n')
         stream.write('Next run:'.ljust(PAD))
         if info['next_run']:
             stream.write(info['next_run'].strftime(_fmt).ljust(20))
             if _now > info['next_run']:
                 stream.write(' (was %s ago)\n' % timesince(info['next_run'], _now))
             else:
                 stream.write(' (in %s)\n' % timesince(_now, info['next_run']))
         else:
             stream.write('none\n')
         if info.get('last_error') not in (None, '{}'):
             last_error = json.loads(info['last_error'])
             stream.write('Error!!'.ljust(PAD) + ' (%s times)\n' % info['error_count'])
             stream.write('Traceback (most recent call last):')
             stream.write('%s %s: %s\n' % (
                 last_error['traceback'], last_error['type'], last_error['value']
             ))
         stream.write('\n')