def _log_run(self, cmd, seconds, time_, last_success, now, exc_type, exc_value, exc_tb): job = Job.objects.get_or_create(app_name=cmd)[0] if not job.first_run: job.first_run = now job.last_run = now if last_success: job.last_success = last_success next_run = None if exc_type: # it errored, try very soon again next_run = now + datetime.timedelta(seconds=ERROR_RETRY_TIME) else: next_run = now + datetime.timedelta(seconds=seconds) if time_: hh, mm = convert_time(time_) next_run = next_run.replace(hour=hh, minute=mm, second=0, microsecond=0) job.next_run = next_run if exc_type: tb = ''.join(traceback.format_tb(exc_tb)) job.last_error = { 'type': exc_type, 'value': str(exc_value), 'traceback': tb, } job.error_count = job.error_count + 1 else: job.last_error = {} job.error_count = 0 job.save()
def _log_run( self, cmd, seconds, time_, last_success, now, exc_type=None, exc_value=None, exc_tb=None, ): job = Job.objects.get_or_create(app_name=cmd)[0] if not job.first_run: job.first_run = now job.last_run = now if last_success: job.last_success = last_success next_run = None if exc_type: # it errored, try very soon again next_run = now + datetime.timedelta(seconds=ERROR_RETRY_TIME) else: next_run = now + datetime.timedelta(seconds=seconds) if time_: hh, mm = convert_time(time_) next_run = next_run.replace(hour=hh, minute=mm, second=0, microsecond=0) job.next_run = next_run if exc_type: tb = "".join(traceback.format_tb(exc_tb)) job.last_error = { "type": exc_type, "value": str(exc_value), "traceback": tb, } job.error_count = job.error_count + 1 else: job.last_error = {} job.error_count = 0 job.save()
def handle(self, **options): cmds = options['jobs'].split(',') job_specs = get_matching_job_specs(cmds) now = timezone.now() for job_spec in job_specs: cmd = job_spec['cmd'] self.stdout.write('Marking %s for success at %s...' % (cmd, now)) next_run = now if job_spec.get('time'): hh, mm = convert_time(job_spec['time']) next_run = next_run.replace(hour=hh, minute=mm, second=0, microsecond=0) job = Job.objects.get_or_create(app_name=cmd)[0] job.first_run = job.first_run if job.first_run is not None else now job.last_success = now job.next_run = next_run job.save()
def handle(self, **options): cmds = options["jobs"].split(",") job_specs = get_matching_job_specs(cmds) now = timezone.now() for job_spec in job_specs: cmd = job_spec["cmd"] self.stdout.write("Marking %s for success at %s..." % (cmd, now)) next_run = now if job_spec.get("time"): hh, mm = convert_time(job_spec["time"]) next_run = next_run.replace(hour=hh, minute=mm, second=0, microsecond=0) job = Job.objects.get_or_create(app_name=cmd)[0] job.first_run = job.first_run if job.first_run is not None else now job.last_success = now job.next_run = next_run job.save()
def test_convert_time_bad(value): with pytest.raises(TimeDefinitionError): convert_time(value)
def test_convert_time(value, expected): assert convert_time(value) == expected