in ingestion-edge/ingestion_edge/publish.py [0:0]
def init_app(app: Sanic) -> Tuple[PublisherClient, SQLiteAckQueue]:
"""Initialize Sanic app with url rules."""
client = get_client(app.config)
q = get_queue(app.config)
# get metadata_headers config
metadata_headers = app.config["METADATA_HEADERS"]
# validate attribute keys
for attribute in metadata_headers.values():
if len(attribute.encode("utf8")) > 256:
# https://cloud.google.com/pubsub/quotas#resource_limits
raise ValueError("Metadata attribute exceeds key size limit of 256 bytes")
# add routes for ROUTE_TABLE
handlers: Dict[str, Callable] = {}
for route in app.config["ROUTE_TABLE"]:
if route.topic not in handlers:
# generate one handler per topic
handlers[route.topic] = partial(
submit,
client=client,
q=q,
topic=route.topic,
metadata_headers=metadata_headers,
)
handlers[route.topic].__name__ = f"submit({route.topic})"
app.add_route(
handler=handlers[route.topic],
uri=route.uri,
methods=[method.upper() for method in route.methods],
)
return client, q