cubicweb-celery


Namecubicweb-celery JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://forge.extranet.logilab.fr/cubicweb/cubes/celery
SummaryCelery cube
upload_time2023-01-16 14:15:33
maintainer
docs_urlNone
authorLogilab
requires_python
licenseLGPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===============
CubicWeb Celery
===============

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.

.. _trunk: https://github.com/cyberdelia/trunk


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

.. Note:: In order to have the task automatically available by the
          celery worker, you must ensure that it is in a
          Python file that is automatically loaded by CubicWeb, best
          candidate being the ``sobjects`` module of a cube (see the
          `CubicWeb's regitry documentation`_).


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


.. _`CubicWeb's regitry documentation`: https://docs.cubicweb.org/book/intro/concepts.html#the-registry
.. _Operation: https://docs.cubicweb.org/book/devrepo/repo/hooks.html#operations



            

Raw data

            {
    "_id": null,
    "home_page": "https://forge.extranet.logilab.fr/cubicweb/cubes/celery",
    "name": "cubicweb-celery",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Logilab",
    "author_email": "contact@logilab.fr",
    "download_url": "https://files.pythonhosted.org/packages/9c/77/ecc5ae22679e0518f448ca3398b7e22d0fbf1b8af882d91f427a50653322/cubicweb-celery-1.1.0.tar.gz",
    "platform": null,
    "description": "===============\nCubicWeb Celery\n===============\n\nCelery integration with CubicWeb\n\nGetting Started\n---------------\n\nEnable the 'celery' cube in your ``myapp`` cubicweb instance::\n  \n  $ cubicweb-ctl shell myapp\n  entering the migration python shell\n  just type migration commands or arbitrary python code and type ENTER to execute it\n  type \"exit\" or Ctrl-D to quit the shell and resume operation\n  >>> add_cube('celery')\n  >>> ^D\n\nIf needed, configure the broker_url in ``all-in-one.conf``. By\ndefault, and only when using a postgresql database, the trunk_\ntransport will be used for the broker; make sure it is installed.\n\n.. _trunk: https://github.com/cyberdelia/trunk\n\n\nWrite a task::\n\n  from cubicweb_celery import app\n\n  @app.cwtask\n  def ping(self):\n      return 'pong'\n\n  @app.cwtask\n  def users(self):\n      return [str(x[0]) for x in self.cw_cnx.execute('String L WHERE U login L')]\n\n\nor as a class::\n\n    from cubicweb_celery import app\n\n    class MyTask(app.Task):\n        need_cnx = True  # if false (the default), self.cw_cnx will not be set\n                         # before running the task\n\n        def run(self):\n            self.cw_cnx.execute('Any X WHERE ...')\n\n.. Note:: In order to have the task automatically available by the\n          celery worker, you must ensure that it is in a\n          Python file that is automatically loaded by CubicWeb, best\n          candidate being the ``sobjects`` module of a cube (see the\n          `CubicWeb's regitry documentation`_).\n\n\nThen start a celery worker::\n\n    celery -A cubicweb_celery -i INSTANCE_NAME worker [ --beat ]\n\n\nThen you can make the worker execute a task by calling it, eg. from\nan Operation_. You may also run a task from a ``cubicweb-ctl shell``::\n\n  $ cubicweb-ctl shell myapp\n  >>> from cubes.myapp.sobjects import ping, users\n  >>> print ping.delay().wait()\n  'pong'\n  >>> print users.delay().wait()\n  ['anon', 'admin']\n\n\n.. _`CubicWeb's regitry documentation`: https://docs.cubicweb.org/book/intro/concepts.html#the-registry\n.. _Operation: https://docs.cubicweb.org/book/devrepo/repo/hooks.html#operations\n\n\n",
    "bugtrack_url": null,
    "license": "LGPL",
    "summary": "Celery cube",
    "version": "1.1.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc8735f96a582d9c276c8cdda51a5644f433013d8ef49d9a7f4600bfd91a97ec",
                "md5": "67d4e6f7504a25efca78b8e2314449c2",
                "sha256": "42fef0a5a0befada0d3a089022ba5d2800f271c80ccd1c94c12024465f8831e8"
            },
            "downloads": -1,
            "filename": "cubicweb_celery-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "67d4e6f7504a25efca78b8e2314449c2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6692,
            "upload_time": "2023-01-16T14:15:31",
            "upload_time_iso_8601": "2023-01-16T14:15:31.711757Z",
            "url": "https://files.pythonhosted.org/packages/bc/87/35f96a582d9c276c8cdda51a5644f433013d8ef49d9a7f4600bfd91a97ec/cubicweb_celery-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c77ecc5ae22679e0518f448ca3398b7e22d0fbf1b8af882d91f427a50653322",
                "md5": "d55bb8fa241b86be41a5932b173b652b",
                "sha256": "970ef2fb5c7430f87459580b694468f08fe89a7697a4bfc3fbf9369ca532e879"
            },
            "downloads": -1,
            "filename": "cubicweb-celery-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d55bb8fa241b86be41a5932b173b652b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8106,
            "upload_time": "2023-01-16T14:15:33",
            "upload_time_iso_8601": "2023-01-16T14:15:33.393284Z",
            "url": "https://files.pythonhosted.org/packages/9c/77/ecc5ae22679e0518f448ca3398b7e22d0fbf1b8af882d91f427a50653322/cubicweb-celery-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 14:15:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "cubicweb-celery"
}
        
Elapsed time: 0.02818s