未提供项目描述
项目描述
关于tgext.celery
tgext.celery是一个TurboGears2扩展,它将celery集成到TurboGears应用中
我仅使用celery[mongodb]==3.1的celery捆绑包和pymongo==3.5.1进行了此扩展的测试,使用mongodb作为消息代理和结果后端
集成了celery beat和celery worker
安装
tgext.celery可以从PyPI安装
pip install tgext.celery
应该适用于大多数用户。
插件
要启用tgext.celery,请将以下内容放入您的应用内的config/app_cfg.py
from tgext.pluggable import plug plug(base_config, 'tgext.celery')
在您的*.ini文件中,将您想要传递给celery应用的选项以`celery.`为前缀添加
#celery config celery.CELERY_TASK_SERIALIZER = json celery.CELERY_RESULT_SERIALIZER = json celery.CELERY_ACCEPT_CONTENT = json celery.CELERY_TIMEZONE = UTC celery.BROKER_URL = mongodb://localhost:27017/dbname celery.CELERY_RESULT_BACKEND = mongodb://localhost:27017/dbname celery.CELERYD_POOL = celery.concurrency.threads.TaskPool celery.CELERY_INCLUDE = myproject.lib.celery.tasks celery.CELERYD_CONCURRENCY = 3 celery.WITHOUT_GOSSIP = true celery.WITHOUT_HEARTBEAT = true celery.WITHOUT_MINGLE = true
有关其他选项,请参阅http://docs.celeryproject.org/en/3.1/configuration.html#configuration
禁用gossip,heartbeat和mingle只能从celery worker cli中进行,我们已将它们添加到配置中。如果您不使用监控工具,我们建议您禁用它们,因为存在一个错误:https://github.com/celery/celery/issues/1047,该错误会将GB级别的消息填充到您的数据库中。
您可以在插入此扩展时传递其他选项(这将覆盖.ini文件中的其他选项),这很方便,因为.ini文件中的选项不会被评估
plug( base_config, 'tgext.celery', celery_config={ 'CELERY_MONGODB_BACKEND_SETTINGS': { 'database': 'dbname', }, 'CELERYBEAT_SCHEDULE': { 'delete-unassociated-images-every-12-hours': { 'task': 'delete_unassociated_images', 'schedule': timedelta(hours=12), }, }, }, )
编写任务
请记住设置CELERY_INCLUDE选项,以下是一个带有任务的示例
from __future__ import absolute_import from myproject import model from tgext.celery.celery import celery_app import logging logger = logging.getLogger(__name__) celery_app.config_from_object(config['celery_configuration_object']) @celery_app.task(name='delete_unassociated_images') def delete_unassociated_images(): logger.info('started') model.Image.query.remove({'post_id': None}) logger.info('finished')
执行
tgext.celery设置了两个gearbox命令,您可以使用以下命令运行celery
gearbox celeryworker -c production.ini --logfile=/var/log/circus/myproject_celery_worker_tasks.log
和
gearbox celerybeat -c production.ini
在生产环境中,您应该将这些命令放在circus watcher或supervisord中
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
tgext.celery-0.1.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1607547bd7f431646cb1e6f76e4af8f3d4094e61847e57bb51bc2220c942660a |
|
MD5 | 38a44b6bf0c73336eca51527a7b00366 |
|
BLAKE2b-256 | 91f5ac388681f39f95dab412fedb607bd1a1083a5aa6b802eae7d190639abdaf |
tgext.celery-0.1.2-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2119ee3a68cab82199d51efbb2c9236bee180d59f6648041f073fc966c10b31c |
|
MD5 | 00229410b473e3ac3a32cdf23380fa46 |
|
BLAKE2b-256 | f0533888f6918f5a04daa4df14eb41d977efa3bf1ca9f968be940b0f54114f5f |