Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The idea I'm exploring is replacing the RouteDispatcher class with a simple Subscribe/Post Event pattern between the Route handler, Transaction processor, and database. Attempting to implement an EventManager has raised a few issues:
Although the motivation for doing this was to reduce code coupling (through the RouteDispatcher class), it's actually caused a circular import. The function to register events imports the EventManager instance created in app.py, which is breaking things.
I had a crude version working previously that used simple functions and a dictionary in a module (events.py). I could watch the subscribers dictionary filling up during app initialisation, but when I came to post_events after starting uivicorn, the dictionary was empty. So something I'm assuming is global isn't. Why is that, and how best to structure this? I created a class so an instance could hold the state, but passing this around caused the circular import.
There are a few global objects floating around - the database, the route dispatcher (when I was using it), this event manager - where do these live?
Stupid one. A tutorial online advised resolving circular imports by importing a whole module (event_manager.EventManager() ) rather than from it (from event_manager import EventManager()). I realised I've no idea what's happening - I couldn't refer to event_manager.EventManager().
in
server/routes/accounts.py
I can call post_event when the api is called. But how do I get the results back to return to FastAPI? How does the thing posting an event get the results of all the listeners doing their thing? Presumably it also has to subscribe to an event that is posted after everything is done?