Replies: 1 comment
-
You can use a class-based namespace for this. Something like this: class MyNamespace(Namespace):
def on_event_one(self, data):
pass
def on_event_two(self, data):
pass
def trigger_event(self, event, *args): # this is called for all events
super().trigger_event(event, *args) # this will dispatch the event to the proper method
db.session.remove() # cleanup code |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
We're using flask-sqlalchemy as well as flask-socketio, and are running into a problem where we have some lingering db sessions. These are a little tricky to track down where you may have forgotten to commit / rollback and close a session, so it'd be easiest if we could have a handler for after every event.
Likewise, it'd be nice to add some logging for every event we receive.
Describe the solution you'd like
Similar to flask's
@app.before_request
&@app.after_request
, it'd be nice if there was a@flask_socketio.before_event
and@flask_socketio.after_event
that fired for every event the socket gets.Describe alternatives you've considered
Manually adding function calls to the beginning and end of every
on
. Doable, but unenforceable and prone to making a mistake.Beta Was this translation helpful? Give feedback.
All reactions