def _get_server_id_and_state(query_history): """ _get_server_id_and_state(query_history) -> (server_id, state_enum) Front-end wrapper to handle exceptions. Expects the query to be submitted. """ ok, server_id = query_history.get_server_id() if not server_id: if ok: raise PopupException("Query is still being submitted to the Beeswax Server") raise PopupException("Failed to retrieve query state from the Beeswax Server") state = db_utils.get_query_state(query_history) if state is None: raise PopupException("Failed to contact Beeswax Server to check query status") return (server_id, state)
def _update_query_state(query_history): """ Update the last_state for a QueryHistory object. Returns success as True/False. This only occurs iff the current last_state is submitted or running, since the other states are stable, more-or-less. Note that there is a transition from available/failed to expired. That occurs lazily when the user attempts to view results that have expired. """ if query_history.last_state <= models.QueryHistory.STATE.running.index: state_enum = db_utils.get_query_state(query_history) if state_enum is None: # Error was logged at the source return False query_history.save_state(state_enum) return True