def reset(job_id): job = Job.query.get(job_id) if job: if job.status in ['active', 'waiting']: logging.error("Job {0} is running".format(job_id)) response = jsonify({ 'code': 400, 'message': "This job is running, stop it first." }) response.status_code = 400 return response else: log = "Status changed from {0} to {1}".format( job.status, 'waiting') job.status = 'waiting' job.tasks_status = json.dumps({ 'count': job.tasks.count(), 'completed': 0, 'failed': 0, 'canceled': 0 }) job.date_edit = datetime.now() db.session.commit() log_to_database(job_id, 'job', log) TaskApi.delete_tasks(job.id) TaskApi.create_tasks(job) logging.info('Job {0} reset end ready'.format(job_id)) else: logging.error("Job {0} not found".format(job_id)) raise KeyError
def reset(job_id): job = Job.query.get(job_id) if job: if job.status in ['active', 'waiting']: logging.error("Job {0} is running".format(job_id)) response = jsonify({ 'code' : 400, 'message': "This job is running, stop it first."}) response.status_code = 400 return response else: log = "Status changed from {0} to {1}".format(job.status, 'waiting') job.status = 'waiting' job.tasks_status = json.dumps({ 'count': job.tasks.count(), 'completed': 0, 'failed': 0, 'canceled': 0}) job.date_edit = datetime.now() db.session.commit() log_to_database(job_id, 'job', log) TaskApi.delete_tasks(job.id) TaskApi.create_tasks(job) logging.info('Job {0} reset end ready'.format(job_id)) else: logging.error("Job {0} not found".format(job_id)) raise KeyError
def reset(job_id): job = Job.query.get(job_id) if job: if job.status == 'running': logging.error("Job {0} is running".format(job_id)) response = jsonify({ 'code' : 400, 'message': "This job is running, stop it first."}) response.status_code = 400 return response else: log = "Status changed from {0} to {1}".format(job.status, 'ready') job.status = 'ready' job.date_edit = datetime.now() db.session.commit() log_to_database(job_id, 'job', log) TaskApi.delete_tasks(job.id) TaskApi.create_tasks(job) # Security check # insecure_names = [None, "", "/", "\\", ".", ".."] # path = join(job.project.render_path_server, str(job.id)) # if job.project.render_path_server not in insecure_names and str(job.id) not in insecure_names: # if exists(path): # rmtree(path) logging.info('Job {0} reset end ready'.format(job_id)) else: logging.error("Job {0} not found".format(job_id)) raise KeyError
def archive(job_id): logging.info('Archiving job {0}'.format(job_id)) job = Job.query.get(job_id) if job.status not in ['active', 'waiting']: log = "Status changed from {0} to {1}".format(job.status, 'archived') job.status = 'archived' db.session.commit() log_to_database(job_id, 'job', log) else: pass
def stop(job_id): logging.info("Stopped job {0}".format(job_id)) # first we stop the associated tasks (no foreign keys) job = Job.query.get(job_id) if job: if job.status not in ['canceled', 'completed', 'failed']: log = "Status changed from {0} to {1}".format(job.status, 'canceled') job.status = 'canceled' job.date_edit = datetime.now() db.session.add(job) db.session.commit() log_to_database(job_id, 'job', log) TaskApi.stop_tasks(job.id) else: logging.error("Job {0} not found".format(job_id)) raise KeyError
def start(job_id): job = Job.query.get(job_id) if job: if job.status not in ['active', 'waiting', 'completed']: log = "Status changed from {0} to {1}".format(job.status, 'waiting') job.date_edit = datetime.now() job.status = 'waiting' db.session.query(Task)\ .filter(Task.job_id == job_id)\ .filter(or_(Task.status == 'canceled', Task.status == 'failed'))\ .update({'status': 'waiting'}) db.session.commit() log_to_database(job_id, 'job', log) else: logging.error("Job {0} not found".format(job_id)) raise KeyError
def reset(job_id): job = Job.query.get(job_id) if job: if job.status in ['active', 'waiting']: logging.error("Job {0} is running".format(job_id)) response = jsonify({ 'code' : 400, 'message': "This job is running, stop it first."}) response.status_code = 400 return response else: log = "Status changed from {0} to {1}".format(job.status, 'waiting') job.status = 'waiting' job.tasks_status = json.dumps({ 'count': job.tasks.count(), 'completed': 0, 'failed': 0, 'canceled': 0}) job.date_edit = datetime.now() db.session.commit() log_to_database(job_id, 'job', log) TaskApi.delete_tasks(job.id) TaskApi.create_tasks(job) # Security check # insecure_names = [None, "", "/", "\\", ".", ".."] # path = join(job.project.render_path_server, str(job.id)) # if job.project.render_path_server not in insecure_names and str(job.id) not in insecure_names: # if exists(path): # rmtree(path) logging.info('Job {0} reset end ready'.format(job_id)) else: logging.error("Job {0} not found".format(job_id)) raise KeyError