Hi,
I’m trying to set up secret handling between the main process and workers. My aim is to have the main process retrieve the secrets and then pass them to the workers, so they don’t need to retrieve them separately.
I’ve tried to do this using the app context, but it doesn’t work.
@sanic.main_process_start
async def main_process_start(app) -> None:
app.ctx.secrets = load_secrets()
@sanic.before_server_start
async def before_server_start(app) -> None:
print(app.ctx.secrets)
When before_server_starts is called I get an AttributeError as secrets doesn’t exist on ctx. If I change ctx to shared_ctx it does appear to work, but there as big scary message about not sharing simple data types that way.
What is the preferred way to do this? Is there any advice on secret management specifically, or sharing simple, static data between main and worker processes more generally?
Many thanks,
Andrew