element-hq / element-hq/synapse
Create a way for modules to run async code at startup
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#12433](https://github.com/matrix-org/synapse/issues/12433).
---
Some modules might want to run some async code at startup, to e.g. set up their database tables before any code accessing this table can be called (to avoid races). Currently the only way to do so is to run that code inside `run_in_background`, which can be prone to races.
It looks to me like it would be simple enough to add an async `setup` callback somewhere around [here](https://github.com/matrix-org/synapse/blob/e24ff8ebe3d4119d377355402245947f7de61c00/synapse/app/_base.py#L434-L444) that allows modules to run async code before e.g. listeners start.
Contributor guide
Assessment
This issue has not been assessed yet.