Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Sending messages to channels via celery #28

Closed
caronc opened this issue Jun 6, 2017 · 3 comments
Closed

Sending messages to channels via celery #28

caronc opened this issue Jun 6, 2017 · 3 comments

Comments

@caronc
Copy link
Contributor

caronc commented Jun 6, 2017

I'm experiencing a very similar problem to this one in my Django Development/Testing environment with the following configuration:

# settings.py
CHANNEL_LAYERS = {
    "default": {
        # This example app uses the Redis channel layer implementation
        # asgi_inmemory
        "BACKEND": "asgiref.inmemory.ChannelLayer",
        "ROUTING": "mytest.routing.channel_routing",
    },
}

My Problem: A scheduled (Celery) task can not send a web socket request through channels. However, it works great in views and other locations. The symptoms are present both with the immediately=True setting and without it. There is no error or anything; the web socket request is just simply not passed along. However having a signal generated from within a model/view works awesome (so i know my setup is good - or so i think).

# from within a celery task (this will just silently fail and not fire to the client):
Group("test").send({
    "text": json.dumps({
        'type': 'test',
    })
}, immediately=True)

# nothing gets sent to the user at this point

I'm launching a celery worker (before starting Django) like so:

   DJANGO_SETTINGS_MODULE=myapp.settings celery --app=myapp worker --beat \
      -l debug \
      --concurrency=1 \
      -Q celery,testqueueA,testqueueB \
      --pidfile for_killing_later.pid &

Was just curious if there was something i was missing here? My package versions are:

  • Django==1.10.7
  • channels==1.1.3
  • asgi-redis==1.4.0
  • asgi-ipc==1.4.0
  • daphne==1.2.0
  • asgiref==1.1.2
  • celery==3.2.1

Any help and/or advice would be most welcome!

@andrewgodwin
Copy link
Member

Are you running inside of Docker?

@andrewgodwin
Copy link
Member

Oh, wait, I've just seen you are using the inmemory channel layer - this does not work between processes (and you've also got the wrong repo anyway). Switch to the IPC or Redis layers and you'll be able to talk between processes.

@caronc
Copy link
Contributor Author

caronc commented Jun 6, 2017

i feel stupid now 😊 ; asgi_ipc is working as expected. Thank you for such a fast reply and pointing out my mistake!

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

No branches or pull requests

2 participants