django / channels

Developer-friendly asynchrony for Django
https://channels.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.01k stars 793 forks source link

django-q2 and django-channels together #2078

Closed jankrnavek closed 4 months ago

jankrnavek commented 4 months ago

Hi, I am trying to run django-q2 and django-channels together but it fails. Everything only works fine with qcluster in sync mode (sync=True)

My chain calls: Regular django app -> async_task with hook -> hook that send channels message.

Any thoughts what can be wrong?

# asycn_task
def create_auto_snapshot(grid_uid: str):
   # do some work with django orm

    return new_grid_uid
# hook called from task
def hook_create_auto_snapshot(task):
    grid_uid = task.result

    # Send notification to all clients in the group
    channel_layer = get_channel_layer()
    channel_group_name = f"grid_group_{grid_uid}"

    async_to_sync(channel_layer.group_send)(
        channel_group_name,
        {"type": "send_notification"},
    )
carltongibson commented 4 months ago

Did you work it out?