def check_job(request, uid): job = Job.objects.filter(uid=uid).first() check_back = 'check_back' if job.state in [Job.SPOOLED, Job.RUNNING] else '' stdout_path = os.path.join(job.path, settings.JOB_STDOUT) stderr_path = os.path.join(job.path, settings.JOB_STDERR) try: state_changed = int(request.GET.get('state')) != job.state except Exception as exc: logger.error(f'Error checking job:{exc}') state_changed = False if os.path.exists(stdout_path) and os.path.exists(stderr_path): stdout = open(stdout_path, 'r').read() stderr = open(stderr_path, 'r').read() Job.objects.filter(uid=job.uid).update(stderr_log=stderr, stdout_log=stdout) else: stdout = stderr = None # Render the updated image icon redir = job.url() if job.is_finished() else "" context = dict(job=job) tmpl = loader.get_template('widgets/loading_img.html') image_tmpl = tmpl.render(context=context) # Render the updated elapsed runtime, status, etc.. context = dict(job=job, check_back=check_back) tmpl = loader.get_template('widgets/job_elapsed.html') template = tmpl.render(context=context) return ajax_success(msg='success', redir=redir, html=template, state=job.get_state_display(), is_running=job.is_running(), stdout=stdout, stderr=stderr, job_color=auth.job_color(job), state_changed=state_changed, img_tmpl=image_tmpl)
def job_color(job): """ Returns a color based on job status. """ return auth.job_color(job)