Skip to content

Instantly share code, notes, and snippets.

@anandtripathi5
Created March 3, 2022 23:36
Show Gist options
  • Save anandtripathi5/82b4d4289a901c71e37096aa1c8f4a68 to your computer and use it in GitHub Desktop.
Save anandtripathi5/82b4d4289a901c71e37096aa1c8f4a68 to your computer and use it in GitHub Desktop.
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