def application(environ, start_response): """The wsgi callback.""" info = environ['PATH_INFO'] if info and info == '/get_state': job_id = get_job_id(environ) record = read_state(job_id) if record: status, response_headers, response_body = create_state_return(record) start_response(status, response_headers) return [response_body] elif info and info == '/upload': #celery_is_alive = ping_celery() celery_is_alive = True if celery_is_alive: # get temporary id from id server job_id = get_unique_id(1, 'upload_job') update_state(job_id, 'OK', 'UPLOADING', 0) try: filepath = receive(environ, job_id) except Exception, e: update_state(job_id, 'FAILED', 'receive bundle', 100) if filepath != '': start_ingest(job_id, filepath) record = read_state(job_id) else: record = IngestState() record.state = 'ERROR: Celery is dead' record.job_id = -99 if record: status, response_headers, response_body = create_state_return(record) start_response(status, response_headers) return [response_body]
def application(environ, start_response): """The wsgi callback.""" create_tables() info = environ['PATH_INFO'] if info and info == '/get_state': job_id = get_job_id(environ) try: record = read_state(job_id) except peewee.DoesNotExist: status, response_headers, response_body = create_invalid_return() start_response(status, response_headers) return [response_body] if record: status, response_headers, response_body = create_state_return( record) start_response(status, response_headers) return [response_body] elif info and info == '/upload': # celery_is_alive = ping_celery() celery_is_alive = True if celery_is_alive: # get temporary id from id server job_id = get_unique_id(1, 'upload_job') update_state(job_id, 'OK', 'UPLOADING', 0) try: filepath = receive(environ, job_id) # pylint: disable=broad-except except Exception as exc: update_state(job_id, 'FAILED', 'receive bundle', 0, str(exc)) status = '500 Internal Server Error' record = read_state(job_id) response_body = create_state_response(record) response_headers = [('Content-Type', 'application/json'), ('Content-Length', str(len(response_body))) ] start_response(status, response_headers) return [response_body] # pylint: enable=broad-except if filepath != '': start_ingest(job_id, filepath) record = read_state(job_id) else: record = IngestState() record.state = 'ERROR: Celery is dead' record.job_id = -99 if record: status, response_headers, response_body = create_state_return( record) start_response(status, response_headers) return [response_body] else: status, response_headers, response_body = create_invalid_return() start_response(status, response_headers) return [response_body] status, response_headers, response_body = create_invalid_return() start_response(status, response_headers) return [response_body]