Created
March 3, 2022 23:36
-
-
Save anandtripathi5/82b4d4289a901c71e37096aa1c8f4a68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_socketio import emit, join_room | |
from extensions import db | |
from base import BaseSocket | |
class Foo(BaseSocket): | |
def on_get_foo_details(self, **kwargs): | |
try: | |
# Do something useful like print statement | |
print("Hello! Awesome world") | |
# Then send a event back to the world | |
join_room("user-1-room", namespace=self.namespace) | |
some_celery_task.delay(room_name="user-1-room", namespace="/foo") | |
emit("event_name", dict(random_key="random_value"), namespace=self.namespace) | |
# or | |
emit("event_name", dict(random_key="random_value")) | |
except Exception as e: | |
print("Catch the exception") | |
# Db session remove is important | |
db.session.remove() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment