celery.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. .. currentmodule:: celery
  2. .. automodule:: celery
  3. .. contents::
  4. :local:
  5. Application
  6. -----------
  7. .. class:: Celery(main=None, broker="amqp://guest:guest@localhost:5672//",
  8. loader="app", backend=None)
  9. :param main: Name of the main module if running as `__main__`.
  10. :keyword broker: URL of the default broker used.
  11. :keyword loader: The loader class, or the name of the loader class to use.
  12. Default is :class:`celery.loaders.app.AppLoader`.
  13. :keyword backend: The result store backend class, or the name of the
  14. backend class to use. Default is the value of the
  15. :setting:`CELERY_RESULT_BACKEND` setting.
  16. :keyword amqp: AMQP object or class name.
  17. :keyword events: Events object or class name.
  18. :keyword log: Log object or class name.
  19. :keyword control: Control object or class name.
  20. :keyword set_as_current: Make this the global current app.
  21. :keyword tasks: A task registry or the name of a registry class.
  22. .. attribute:: main
  23. Name of the `__main__` module. Required for standalone scripts.
  24. If set this will be used instead of `__main__` when automatically
  25. generating task names.
  26. .. attribute:: conf
  27. Current configuration.
  28. .. attribute:: amqp
  29. AMQP related functionality: :class:`~@amqp`.
  30. .. attribute:: backend
  31. Current backend instance.
  32. .. attribute:: loader
  33. Current loader instance.
  34. .. attribute:: control
  35. Remote control: :class:`~@control`.
  36. .. attribute:: events
  37. Consuming and sending events: :class:`~@events`.
  38. .. attribute:: log
  39. Logging: :class:`~@log`.
  40. .. attribute:: tasks
  41. Task registry.
  42. .. attribute:: pool
  43. Broker connection pool: :class:`~@pool`.
  44. .. attribute:: Task
  45. Base task class for this app.
  46. .. method:: bugreport
  47. Returns a string with information useful for the Celery core
  48. developers when reporting a bug.
  49. .. method:: config_from_object(obj, silent=False)
  50. Reads configuration from object, where object is either
  51. an object or the name of a module to import.
  52. :keyword silent: If true then import errors will be ignored.
  53. .. code-block:: python
  54. >>> celery.config_from_object("myapp.celeryconfig")
  55. >>> from myapp import celeryconfig
  56. >>> celery.config_from_object(celeryconfig)
  57. .. method:: config_from_envvar(variable_name, silent=False)
  58. Read configuration from environment variable.
  59. The value of the environment variable must be the name
  60. of a module to import.
  61. .. code-block:: python
  62. >>> os.environ["CELERY_CONFIG_MODULE"] = "myapp.celeryconfig"
  63. >>> celery.config_from_envvar("CELERY_CONFIG_MODULE")
  64. .. method:: config_from_cmdline(argv, namespace="celery")
  65. Parses argv for configuration strings.
  66. Configuration strings must be located after a '--' sequence,
  67. e.g.::
  68. program arg1 arg2 -- celeryd.concurrency=10
  69. :keyword namespace: Default namespace if omitted.
  70. .. method:: start(argv=None)
  71. Run :program:`celery` using `argv`.
  72. Uses :data:`sys.argv` if `argv` is not specified.
  73. .. method:: task(fun, **options)
  74. Decorator to create a task class out of any callable.
  75. **Examples:**
  76. .. code-block:: python
  77. @task
  78. def refresh_feed(url):
  79. return ...
  80. with setting extra options:
  81. .. code-block:: python
  82. @task(exchange="feeds")
  83. def refresh_feed(url):
  84. return ...
  85. .. admonition:: App Binding
  86. For custom apps the task decorator returns proxy
  87. objects, so that the act of creating the task is not performed
  88. until the task is used or the task registry is accessed.
  89. If you are depending on binding to be deferred, then you must
  90. not access any attributes on the returned object until the
  91. application is fully set up (finalized).
  92. .. method:: send_task(name, args=(), kwargs={}, countdown=None,
  93. eta=None, task_id=None, publisher=None, connection=None,
  94. result_cls=AsyncResult, expires=None, queues=None, **options)
  95. Send task by **name**.
  96. :param name: Name of task to execute (e.g. `"tasks.add"`).
  97. :keyword result_cls: Specify custom result class. Default is
  98. using :meth:`AsyncResult`.
  99. Otherwise supports the same arguments as :meth:`~@Task.apply_async`.
  100. .. attribute:: AsyncResult
  101. Create new result instance. See :class:`~celery.result.AsyncResult`.
  102. .. attribute:: TaskSetResult
  103. Create new taskset result instance.
  104. See :class:`~celery.result.TaskSetResult`.
  105. .. method:: worker_main(argv=None)
  106. Run :program:`celeryd` using `argv`.
  107. Uses :data:`sys.argv` if `argv` is not specified."""
  108. .. attribute:: Worker
  109. Worker application. See :class:`~@Worker`.
  110. .. attribute:: WorkController
  111. Embeddable worker. See :class:`~@WorkController`.
  112. .. attribute:: Beat
  113. Celerybeat scheduler application.
  114. See :class:`~@Beat`.
  115. .. method:: broker_connection(url="amqp://guest:guest@localhost:5672//",
  116. ssl=False, transport_options={})
  117. Establish a connection to the message broker.
  118. :param url: Either the URL or the hostname of the broker to use.
  119. :keyword hostname: defaults to the :setting:`BROKER_HOST` setting.
  120. :keyword userid: defaults to the :setting:`BROKER_USER` setting.
  121. :keyword password: defaults to the :setting:`BROKER_PASSWORD` setting.
  122. :keyword virtual_host: defaults to the :setting:`BROKER_VHOST` setting.
  123. :keyword port: defaults to the :setting:`BROKER_PORT` setting.
  124. :keyword ssl: defaults to the :setting:`BROKER_USE_SSL` setting.
  125. :keyword insist: defaults to the :setting:`BROKER_INSIST` setting.
  126. :keyword backend_cls: defaults to the :setting:`BROKER_TRANSPORT`
  127. setting.
  128. :returns :class:`kombu.connection.BrokerConnection`:
  129. """
  130. .. method:: default_connection(connection=None)
  131. For use within a with-statement to get a connection from the pool
  132. if one is not already provided.
  133. :keyword connection: If not provided, then a connection will be
  134. acquired from the connection pool.
  135. .. method:: mail_admins(subject, body, fail_silently=False)
  136. Sends an email to the admins in the :setting:`ADMINS` setting.
  137. .. method:: select_queues(queues=[])
  138. Select a subset of queues, where queues must be a list of queue
  139. names to keep.
  140. .. method:: now()
  141. Returns the current time and date as a :class:`~datetime.datetime`
  142. object.
  143. .. method:: set_current()
  144. Makes this the current app for this thread.
  145. .. method:: finalize()
  146. Finalizes the app by loading built-in tasks,
  147. and evaluating pending task decorators
  148. .. attribute:: Pickler
  149. Helper class used to pickle this application.
  150. Grouping Tasks
  151. --------------
  152. .. autofunction:: group
  153. .. autofunction:: chain
  154. .. autofunction:: chord
  155. .. autofunction:: subtask
  156. Proxies
  157. -------
  158. .. data:: current_app
  159. The currently set app for this thread.
  160. .. data:: current_task
  161. The task currently being executed
  162. (only set in the worker, or when eager/apply is used).