Skip to main content

Celery integration with CubicWeb

Project description

Celery integration with CubicWeb

Getting Started

Enable the ‘celery’ cube in your myapp cubicweb instance:

$ 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

If needed, configure the broker_url in all-in-one.conf. By default, and only when using a postgresql database, the trunk transport will be used for the broker; make sure it is installed.

Write a task:

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')]

or as a class:

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 ...')

Then start a celery worker:

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

Then you can make the worker execute a task by calling it, eg. from an Operation. You may also run a task from a 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']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cubicweb-celery-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file cubicweb-celery-0.2.0.tar.gz.

File metadata

File hashes

Hashes for cubicweb-celery-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bcc04fe1cfb8f227b38e767df7be62f7e4eceaa8e9a765d0b88a89af5293760f
MD5 35cd7c3875c95aeaae76d8672518fcae
BLAKE2b-256 bde9f923c8b4f7042ca3dbfc9d676f8cde5aba747b202a4bc3d716f9d2c9cea6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page