def function_handler()

in source/machine_connector/m2c2_opcda_connector/m2c2_opcda_connector.py [0:0]


def function_handler(connection_data, context):
    """OPC DA Connector function handler."""

    global lock

    try:
        if not lock:
            lock = True
            connection_control = connection_data["control"].lower()
            set_connection_properties(connection_data)

            if connection_control == "start":
                if connector_client.is_running:
                    post_to_user("info", msg.ERR_MSG_FAIL_LAST_COMMAND_START.format(connection_name))
                else:
                    start(connection_data)
            elif connection_control == "stop":
                if connector_client.is_running:
                    stop()
                else:
                    post_to_user("info", msg.ERR_MSG_FAIL_LAST_COMMAND_STOP.format(connection_name))
            elif connection_control == "update":
                update(connection_data)
            elif connection_control == "push":
                push(connection_data)
            elif connection_control == "pull":
                pull()
            else:
                post_to_user("error", msg.ERR_MSG_FAIL_UNKWOWN_CONTROL.format(connection_control))

            lock = False
        else:
            logger.info("The function is still processing.")
    except Exception as err:
        logger.error("Failed to run the connection on the function: %s", str(err))

        if type(err).__name__ != "KeyError":
            post_to_user("error", "Failed to run the connection: {}".format(str(err)))

        lock = False
        connector_client.stop_client()

        raise