Jango的“PQ”包装
dj-pq的Python项目详细描述
pqdjango的包装。
安装
pip install dj-pq
配置
将dj_pq添加到INSTALLED_APPS:
INSTALLED_APPS+=['dj_pq',]
应用迁移:
./manage.py migrate
用法
dj-pq公开pq tasks API。
fromdj_pqimportget_queuequeue=get_queue('notifications')@queue.task()defnotify(user_id):User.objects.get(id=user_id).notify()notify(42)
可以选择将Queue绑定到特定的数据库连接:
queue=get_queue('notifications','another_connection')
worker命令允许为给定队列启动工作进程:
./manage.py worker notifications