Django Channels and Celery Example

本项目展示了如何使用 Celery 任务队列设置 Django Channels 项目。「This project shows how to setup a Django Channels project with a Celery task queue.」

Github星跟蹤圖

Django Channels and Celery Example

This project shows how to setup a Django Channels project with a Celery task queue. The user can start a long running background task and get immediate notification when the task completes without a browser refresh.

You can see an example deployment at http://tasker.vincenttide.com. Note that this deployment contains some extra stuff not covered in this repository.

To run this project you will need to install Redis. It is used both as the Channels layer backend and as the Celery broker.

Then just run:

pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py runserver  # Start daphne and workers
celery worker -A example -l info  # Start celery workers

How to Send Reply Back to Browser Client

The code block below shows how to send a reply back to the browser that originated the task request. message.reply_channel.name contains a unique address in the form of websocket.send!hjnsMbQPiefT.

Channel(reply_channel).send({
    "text": json.dumps ({
        "action": "completed",
        "job_id": job.id,
        "job_name": job.name,
        "job_status": job.status,
    })
})

主要指標

概覽
名稱與所有者VincentTide/django-channels-celery-example
主編程語言Python
編程語言Python (語言數: 2)
平台
許可證
所有者活动
創建於2016-07-21 00:32:31
推送於2017-12-27 01:51:48
最后一次提交2016-08-21 18:43:11
發布數0
用户参与
星數133
關注者數3
派生數41
提交數14
已啟用問題?
問題數2
打開的問題數1
拉請求數1
打開的拉請求數1
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?