跳转到主要内容

Celery cube

项目描述

CubicWeb与Celery集成

入门指南

在您的 myapp CubicWeb实例中启用‘celery’cube

$ cubicweb-ctl shell myapp
entering the migration python shell
just type migration commands or arbitrary python code and type ENTER to execute it
type "exit" or Ctrl-D to quit the shell and resume operation
>>> add_cube('celery')
>>> ^D

如果需要,在 all-in-one.conf 中配置 broker_url。默认情况下,并且仅当使用postgresql数据库时,将使用 trunk 传输作为代理;请确保已安装。

编写一个任务

from cubicweb_celery import app

@app.cwtask
def ping(self):
    return 'pong'

@app.cwtask
def users(self):
    return [str(x[0]) for x in self.cw_cnx.execute('String L WHERE U login L')]

或者作为一个类

from cubicweb_celery import app

class MyTask(app.Task):
    need_cnx = True  # if false (the default), self.cw_cnx will not be set
                     # before running the task

    def run(self):
        self.cw_cnx.execute('Any X WHERE ...')

然后启动一个celery worker

celery -A cubicweb_celery -i INSTANCE_NAME worker [ --beat ]

然后您可以通过调用它来使worker执行一个任务,例如从一个 操作。您还可以从 cubicweb-ctl shell 运行任务

$ cubicweb-ctl shell myapp
>>> from cubes.myapp.sobjects import ping, users
>>> print ping.delay().wait()
'pong'
>>> print users.delay().wait()
['anon', 'admin']

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定要选择哪一个,请了解更多关于 安装包 的信息。

源分布

cubicweb_celery-1.1.1.tar.gz (8.1 kB 查看哈希值)

上传时间: 源代码

构建分布

cubicweb_celery-1.1.1-py3-none-any.whl (6.7 kB 查看哈希值)

上传时间: Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面