Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription to tasks and listening on / instead of /task-id #4

Open
dmfigol opened this issue Jan 10, 2018 · 4 comments
Open

Subscription to tasks and listening on / instead of /task-id #4

dmfigol opened this issue Jan 10, 2018 · 4 comments

Comments

@dmfigol
Copy link

dmfigol commented Jan 10, 2018

Awesome project, kudos.
It would be great if the client could create a single WebSocket connection to / instead of /task-id, subscribe to task or tasks and then receive events.

@jjl
Copy link

jjl commented Jan 10, 2018

That would be nice.

We don't actually use wscelery anymore since we stopped using celery, but we'd be happy to take patches.

@kalouantonis
Copy link
Contributor

I agree with you, this was on our project roadmap before we moved away from celery.

If you'd like to have a look, you'd need to handle messages in the on_message handler here: https://github.com/johan-sports/wscelery/blob/master/wscelery/websocket.py#L43, removing task_id from the parameters expected here https://github.com/johan-sports/wscelery/blob/master/wscelery/websocket.py#L39 and moving the code that adds the event listener here https://github.com/johan-sports/wscelery/blob/master/wscelery/websocket.py#L41

I was thinking something along the lines of:

class WebSocketHandler(tornado.websocket.WebSocketHandler):
    def initialize(self, events, allow_origin=None):
        self.events = events
        self.listeners = []
        self.allow_origin = allow_origin

    def check_origin(self, origin):
        if not self.allow_origin:
            return super().check_origin(origin)
        match = re.match(self.allow_origin, origin)
        return match is not None

    def _handle_event(self, event):
        self.write_message(parse_event(event))


    def on_message(self, task_id):
        self.listeners.append(task_id)
        self.events.add_listener(task_id, self._handle_event)
       
    def on_close(self):
        map(self.events.remove_listener, self.listeners)

I don't have time to make these changes and test that the behaviour works as expected, but PR's are more than welcome.

@soer7022
Copy link

@kalouantonis what are you using instead of Celery? I find that all of the frontends for Celery are hopelessly outdated...

@antoniskalou
Copy link

Hey @soer7022, I'm using elixir/erlang nowadays to complete the same tasks without the need for a framework so to speak.

I'd be happy to add maintainers to this project, if anyone is interested, and if @johan-sports agrees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants