def get(self, batch_id): """ Retrieves the state of batch *batch_id*. ** Request ** .. sourcecode:: http GET /batch/:batch_id ** Response ** .. sourcecode:: http HTTP/1.1 200 OK :param batch_id: batch identifier :type batch_id: string :status 200: No error :status 404: No such batch """ log.debug('Routing to batch {} (GET)'.format(batch_id)) res = {} try: batch = SimpleBatch(batch_id) except: return {'message': 'Batch Not Found: {}'.format(batch_id)}, 404 res['pages'] = url_for('api.batchpages', batch_id=batch_id) res['tasks'] = url_for('api.batchtasks', batch_id=batch_id) if batch.is_running(): res['chains'] = batch.get_extended_state() # replace all document tuples with URLs to the page resource def replace_docs(state): for k in state.keys(): if k in ['root_document', 'result', 'doc']: if state[k] is not None and isinstance( state[k][0], list): docs = [] for doc in state[k]: docs.append( url_for('api.page', batch=doc[0], file=doc[1])) state[k] = docs elif state[k] is not None: state[k] = url_for('api.page', batch=state[k][0], file=state[k][1]) if isinstance(state[k], dict): replace_docs(state[k]) replace_docs(res['chains']) return res, 200
def get(self, batch_id): """ Retrieves the state of batch *batch_id*. ** Request ** .. sourcecode:: http GET /batch/:batch_id ** Response ** .. sourcecode:: http HTTP/1.1 200 OK :param batch_id: batch identifier :type batch_id: string :status 200: No error :status 404: No such batch """ log.debug('Routing to batch {} (GET)'.format(batch_id)) res = {} try: batch = SimpleBatch(batch_id) except: return {'message': 'Batch Not Found: {}'.format(batch_id)}, 404 res['pages'] = url_for('api.batchpages', batch_id=batch_id) res['tasks'] = url_for('api.batchtasks', batch_id=batch_id) if batch.is_running(): res['chains'] = batch.get_extended_state() # replace all document tuples with URLs to the page resource def replace_docs(state): for k in state.keys(): if k in ['root_document', 'result', 'doc']: if state[k] is not None and isinstance(state[k][0], list): docs = [] for doc in state[k]: docs.append(url_for('api.page', batch=doc[0], file=doc[1])) state[k] = docs elif state[k] is not None: state[k] = url_for('api.page', batch=state[k][0], file=state[k][1]) if isinstance(state[k], dict): replace_docs(state[k]) replace_docs(res['chains']) return res, 200