def run_jobs(date): """ Start Job and it's tasks """ for pr in Process.objects.filter(is_active=True): must_run = pr.must_run(date) logger.debug(f'process {pr} must run {must_run}') if must_run: try: last_job = Job.objects.filter(process=pr).latest('id') except ObjectDoesNotExist: # job for the process have never run before set an empty job instance # and set status to finished otherwise the overlap validation will avoid # a new instance to start last_job = Job() last_job.status = Job.finished if not pr.run_if_err and last_job.status == Job.error: logger.error( f'job {pr} will not run because previous job status its error' ) continue if not pr.run_overlap and last_job.status == Job.initialized: logger.error( f'job {pr} will not run because previous job has not finished ' f'and this job does not allow overlap') continue __, __ = Job.create(pr)
def post(self, request, *args, **kwargs): try: process = get_object_or_404(Process, id=self.request.POST['process']) __, __ = Job.create(process) except Exception as e: messages.error(request, _(f'{e}')) finally: return request