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']
Release files for cubicweb-celery 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cubicweb_celery-1.2.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cubicweb_celery-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / cubicweb_celery-1.2.0.tar.gz
| Download URL | cubicweb_celery-1.2.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3627d7feb8f1e81ec77261c4062c106ba7d06672700370b97010a796e9f238b2
|
|
BLAKE2b-256 checksum How to use checksums |
159820f88f709f882f9714c242567f66ff6e7bbe2fb56ca66d4f00357965702c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / cubicweb_celery-1.2.0-py3-none-any.whl
| Download URL | cubicweb_celery-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2773e69112459a5707cd6bb9543a1fb648d9788e8c86fdc5071395f39410defd
|
|
BLAKE2b-256 checksum How to use checksums |
b7dde306eadec1e381d9dd15d954bf6c2d25366537b3e292592ce08034763877
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|