示例#1
0
def query_tool_status(trans_id):
    """
    The task of this function to return the status of the current connection
    used in query tool instance with given transaction ID.
    Args:
        trans_id: Transaction ID

    Returns:
        Response with the connection status

        Psycopg2 Status Code Mapping:
        -----------------------------
        TRANSACTION_STATUS_IDLE     = 0
        TRANSACTION_STATUS_ACTIVE   = 1
        TRANSACTION_STATUS_INTRANS  = 2
        TRANSACTION_STATUS_INERROR  = 3
        TRANSACTION_STATUS_UNKNOWN  = 4
    """
    (status, error_msg, conn, trans_obj,
     session_obj) = check_transaction_status(trans_id)

    if not status and error_msg and type(error_msg) == str:
        return internal_server_error(errormsg=error_msg)

    if conn and trans_obj and session_obj:
        status = conn.transaction_status()
        return make_json_response(
            data={
                'status': status,
                'message': gettext(
                    CONNECTION_STATUS_MESSAGE_MAPPING.get(status))
            })
    else:
        return internal_server_error(
            errormsg=gettext("Transaction status check failed."))
示例#2
0
def query_tool_status(trans_id):
    """
    The task of this function to return the status of the current connection
    used in query tool instance with given transaction ID.
    Args:
        trans_id: Transaction ID

    Returns:
        Response with the connection status

        Psycopg2 Status Code Mapping:
        -----------------------------
        TRANSACTION_STATUS_IDLE     = 0
        TRANSACTION_STATUS_ACTIVE   = 1
        TRANSACTION_STATUS_INTRANS  = 2
        TRANSACTION_STATUS_INERROR  = 3
        TRANSACTION_STATUS_UNKNOWN  = 4
    """
    (status, error_msg, conn, trans_obj,
     session_obj) = check_transaction_status(trans_id)

    if not status and error_msg and type(error_msg) == str:
        return internal_server_error(
            errormsg=error_msg
        )

    if conn and trans_obj and session_obj:
        status = conn.transaction_status()
        return make_json_response(
            data={
                'status': status,
                'message': gettext(
                    CONNECTION_STATUS_MESSAGE_MAPPING.get(status)
                )
            }
        )
    else:
        return internal_server_error(
            errormsg=gettext("Transaction status check failed.")
        )