예제 #1
0
    def _get_transport_pool(self,
                            api_name: str,
                            transport_type: str,
                            default=empty) -> AnyTransportPoolType:
        # Get the registry entry for this API (if any)
        registry_entry = self._registry.get(api_name)
        api_transport = None

        # If we have a registry entry for this API, then get the transport for it
        if registry_entry:
            api_transport = getattr(registry_entry, transport_type)

        # Otherwise get the transport for the default API (which is always our fallback)
        # (but don't bother if they have explicity asked for the default_api, as if they
        # have then we've already failed to get that in the previous step)
        if not api_transport and api_name != "default":
            try:
                api_transport = self._get_transport_pool(
                    "default", transport_type)
            except TransportNotFound:
                pass

        # If we STILL don't have a transport then show a sensible error
        if not api_transport and default == empty:
            raise TransportNotFound(
                f"No {transport_type} transport found for API '{api_name}'. Neither was a default "
                f"API transport found. Either specify a {transport_type} transport for this specific API, "
                f"or specify a default {transport_type} transport. In most cases setting a default transport "
                f"is the best course of action.")
        else:
            return api_transport
예제 #2
0
def get_transport(type_, name):
    for name_, class_ in get_available_transports(type_).items():
        if name == name_:
            return class_

    raise TransportNotFound(
        f"No '{type_}' transport found named '{name}'. Check the transport is installed and "
        f"has the relevant entrypoints setup in it's setup.py file. Or perhaps "
        f"you have a typo in your config file.")
예제 #3
0
 def get_schema_transport(self, default=empty) -> SchemaTransportPoolType:
     if self.schema_transport or default != empty:
         return self.schema_transport or default
     else:
         # TODO: Link to docs
         raise TransportNotFound(
             "No schema transport is configured for this bus. Check your schema transport "
             "configuration is setup correctly (config section: bus.schema.transport)."
         )
예제 #4
0
def get_transport_name(cls: Type["Transport"]):
    for type_ in ("rpc", "result", "event"):
        for *_, name, class_ in load_entrypoint_classes(f"lightbus_{type_}_transports"):
            if cls == class_:
                return name

    raise TransportNotFound(
        f"Transport class {cls.__module__}.{cls.__name__} is not specified in any entrypoint."
    )
예제 #5
0
    def _get_transport(self, api_name: str, transport_type: str, default=empty):
        registry_entry = self._registry.get(api_name)
        api_transport = None
        if registry_entry:
            api_transport = getattr(registry_entry, transport_type)

        if not api_transport and api_name != "default":
            try:
                api_transport = self._get_transport("default", transport_type)
            except TransportNotFound:
                pass

        if not api_transport and default == empty:
            raise TransportNotFound(
                f"No {transport_type} transport found for API '{api_name}'. Neither was a default "
                f"API transport found. Either specify a {transport_type} transport for this specific API, "
                f"or specify a default {transport_type} transport. In most cases setting a default transport "
                f"is the best course of action."
            )
        else:
            return api_transport