def wait_query(self, query_execution_id): """ Wait query ends :param query_execution_id: Query execution ID :return: Query response """ final_states = ["FAILED", "SUCCEEDED", "CANCELLED"] response = self._client_athena.get_query_execution( QueryExecutionId=query_execution_id) state = response["QueryExecution"]["Status"]["State"] while state not in final_states: sleep(QUERY_WAIT_POLLING_DELAY) response = self._client_athena.get_query_execution( QueryExecutionId=query_execution_id) state = response["QueryExecution"]["Status"]["State"] logger.debug(f"state: {state}") logger.debug( f"StateChangeReason: {response['QueryExecution']['Status'].get('StateChangeReason')}" ) if state == "FAILED": raise QueryFailed( response["QueryExecution"]["Status"].get("StateChangeReason")) elif state == "CANCELLED": raise QueryCancelled( response["QueryExecution"]["Status"].get("StateChangeReason")) return response
def wait_query(self, query_id): """ Wait query ends :param query_id: Query ID :return: Query results """ final_states = ["Complete", "Failed", "Cancelled"] response = self._client_logs.get_query_results(queryId=query_id) status = response["status"] while status not in final_states: sleep(QUERY_WAIT_POLLING_DELAY) response = self._client_logs.get_query_results(queryId=query_id) status = response["status"] logger.debug(f"status: {status}") if status == "Failed": raise QueryFailed(f"query ID: {query_id}") elif status == "Cancelled": raise QueryCancelled(f"query ID: {query_id}") return response