Skip to main content

Celery cube

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-1.1.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

cubicweb_celery-1.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file cubicweb_celery-1.1.1.tar.gz.

File metadata

  • Download URL: cubicweb_celery-1.1.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for cubicweb_celery-1.1.1.tar.gz
Algorithm Hash digest
SHA256 cfb1c3a8d398bd15e39d76fe689e180bc558b0c4c0fef0b6ce5817101bca3001
MD5 28844efe074db15568c2f2334e48a3f1
BLAKE2b-256 0de2f8c7c977f6bda7b6e09ec5f2076e9fdab562ca1a51fd106d6ee7a1c21611

See more details on using hashes here.

File details

Details for the file cubicweb_celery-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cubicweb_celery-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b5b21be690ee601348c483cadad370b85d9996952cfd3038c76534890f8b4b9
MD5 1b6cb093f66b1a393e81ac1fee8b86c8
BLAKE2b-256 7476e1d9144d6d1a513d177b88a32ed2255fa1b059d1a0d9dcfc1dd23685a062

See more details on using hashes here.

Supported by

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