def get_model_file(job_id): """ Get the pdb file, created by the modeling job. :param jobid: the job_id returned by 'submit' :return: The pdb file created by the job. If the job status is not SUCCESS, this method returns an error. """ from hommod.application import celery result = celery.AsyncResult(job_id) if result.status != 'SUCCESS': return jsonify( {'error': "{} has status {}".format(job_id, result.status)}), 400 try: path = result.get() except Exception: return jsonify({'error': result.traceback}), 500 if path is None: message = 'Job %s finished, but without creating a model. This could be due to lack of a suitable template.' % job_id return jsonify({'error': message}), 500 try: contents = model_storage.extract_model(path) return Response(contents, mimetype='chemical/x-pdb') except: return jsonify({'error': traceback.format_exc()}), 500
def status(job_id): """ Request the status of a job. :param jobid: the job id returned by 'submit' :return: Either PENDING, STARTED, SUCCESS, FAILURE, RETRY, or REVOKED. """ from hommod.application import celery result = celery.AsyncResult(job_id) response = {'status': result.status} if result.failed(): response['message'] = str(result.traceback) return jsonify(response)
def get_metadata(job_id): """ Get the metadata of the model, created by the modeling job. :param jobid: the job_id returned by 'submit' :return: The json metadata object. If the job status is not SUCCESS, this method returns an error. """ from hommod.application import celery result = celery.AsyncResult(job_id) if result.status != 'SUCCESS': return jsonify( {'error': "{} has status {}".format(job_id, result.status)}), 400 try: path = result.get() except Exception: return jsonify({'error': result.traceback}), 500 if path is None: message = 'Job %s finished, but without creating a model. This could be due to lack of a suitable template.' % job_id return jsonify({'error': message}), 500 try: data = {} data['selected_targets'] = model_storage.extract_selected_targets(path) data['alignments'] = [ alignment.as_dict() for alignment in model_storage.extract_alignments(path) ] return jsonify(data) except: return jsonify({'error': traceback.format_exc()}), 500
def result(job_id): """ Request whether a job has created a model or not. :param jobid: the job id returned by 'submit' :return: a json object containing the boolean field 'model_created' """ from hommod.application import celery result = celery.AsyncResult(job_id) if result.status != 'SUCCESS': return jsonify( {'error': "{} has status {}".format(job_id, result.status)}), 400 try: path = result.get() except: return jsonify({'model_created': False}) if path is not None: return jsonify({'model_created': True}) else: return jsonify({'model_created': False})