Celery

Celery 是基于分布式消息传递的异步任务队列/作业队列。 它专注于实时操作,但也支持调度。(Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well. )

Github stars Tracking Chart

Celery 是基于分布式消息传递的异步任务队列/作业队列。 它专注于实时操作,但也支持调度。

什么是任务队列?

任务队列用作跨线程或机器分发工作的机制。

任务队列的输入是一个工作单元,称为任务,专用的工作进程然后不断监视队列以执行新工作。

Celery 通过消息进行通信,通常使用代理(broker)在客户端(clients)和任务消费者(worker)之间进行协调。为了启动任务,客户端将消息放入队列,然后代理将消息传递给任务消费者(worker)。

Celery 系统可以由多个 worker 和代理组成,为高可用性和水平扩展让路。

Celery 是用 Python 编写的,但协议可以用任何语言实现。 除了 Python 之外,还有 Node.js 的 node-celery 和 PHP 客户端。

语言互操作性也可以通过使用 webhook 来实现,通过这种方式,客户端可以对 worker 请求的 URL 进行排队。

我需要什么?

Celery 版本 4.3 运行于

  • Python (2.7, 3.4, 3.5, 3.6, 3.7)
  • PyPy2.7 (6.0)
  • PyPy3.5 (6.0)

Celery 是一个资金很少的项目,因此我们不支持 Microsoft Windows。 请不要打开与该平台相关的任何问题。

Celery 通常与消息代理一起使用来发送和接收消息。 RabbitMQ、Redis 传输功能齐全,但也有许多其他解决方案的实验性支持,包括使用 SQLite 进行本地开发。
Celery 可以在一台机器上运行,也可在多台机器上运行,甚至可以在数据中心运行。

入门

如果这是您第一次尝试使用 Celery,或者您是以前版本的 Celery 4.2 新手,那么您应该阅读我们的入门教程:

Celery 是...

  • 简单
    易于使用和维护,不需要配置文件。它有一个活跃、友好的社区,您可以通过它来获得支持,比如在我们的邮件列表或 IRC 频道。下面是您可以创建的最简单的应用程序之一:
    from celery import Celery
    app = Celery('hello', broker='amqp://guest@localhost//')
    @app.task
    def hello():
        return 'hello world'
            
  • 高可用性
    Workers 和客户机将在连接丢失或失败时自动重试,一些代理以Primary/PrimaryPrimary/Replica 的方式支持HA。
  • 快速
    一个 Celery 进程可以在一分钟内处理数百万个任务,其往返延迟为亚毫秒(使用 RabbitMQ、py-librabbitmq 和优化设置)。
  • 灵活
    Celery 的几乎每个部分都可以扩展或单独使用,定制池实现、序列化器、压缩方案、日志、调度程序、消费者、生产者、代理传输等等。

她支持...

  • 消息传输(Message Transports)
  • 并发(Concurrency)
  • 结果存储(Result Stores)
    • AMQP, Redis
    • memcached
    • SQLAlchemy, Django ORM
    • Apache Cassandra, IronCache, Elasticsearch
  • 序列化(Serialization)
    • pickle, json, yaml, msgpack.
    • zlib, bzip2 compression.
    • 加密消息签名。

框架集成

Celery 很容易与 web 框架集成,其中一些框架甚至有集成包:

Django not needed
Pyramid pyramid_celery
Pylons celery-pylons
Flask not needed
web2py web2py-celery
Tornado tornado-celery

集成包并不是严格必需的,但是它们可以使开发更加容易,有时它们还添加了一些重要的挂钩,比如在fork上关闭数据库连接。

文档

最新的文档 位于 Read The Docs,其中包含用户指南、教程和 API 参考。

安装

您可以通过 Python 包索引(PyPI)或从源代码安装 Celery。

要使用pip安装:

$ pip install -U Celery

Bundles

Celery 还定义了一组 bundle,可用于安装 Celery 和给定功能的依赖项。

您可以使用括号在需求中或在 pip 命令行中指定这些。 可以通过逗号分隔多个包来指定它们。

$ pip install "celery[librabbitmq]"
$ pip install "celery[librabbitmq,redis,auth,msgpack]"

从源代码下载和安装

从 PyPI 下载最新版本的 Celery:

https://pypi.org/project/celery/

您可以通过执行以下操作来安装它:

$ tar xvfz celery-0.0.0.tar.gz
$ cd celery-0.0.0
$ python setup.py构建
#python setup.py install

如果您当前没有使用 virtualenv,则必须以特权用户身份执行最后一个命令。

使用开发版本

With pip

Celery 开发版还需要 kombu、amqp、billiard 和 vine 的开发版本。

您可以使用以下 pip 命令安装这些快照:

$ pip install https://github.com/celery/celery/zipball/master#egg=celery
$ pip install https://github.com/celery/billiard/zipball/master#egg=billiard
$ pip install https://github.com/celery/py-amqp/zipball/master#egg=amqp
$ pip install https://github.com/celery/kombu/zipball/master#egg=kombu
$ pip install https://github.com/celery/vine/zipball/master#egg=vine
With Git

请参阅贡献部分。

Wiki

https://github.com/celery/celery/wiki

许可

该软件是在 New BSD 许可下授权的。有关完整的许可证文本,请参阅顶部分发目录中的许可证文件。

(First edition: vz revised at 2019.08.16)

Overview

Name With Ownercelery/celery
Primary LanguagePython
Program languageMakefile (Language Count: 5)
PlatformLinux, Mac, BSD
License:Other
Release Count240
Last Release Namev5.4.0 (Posted on )
First Release Namev0.1.7 (Posted on )
Created At2009-04-24 11:31:24
Pushed At2024-04-28 17:18:22
Last Commit At
Stargazers Count23.5k
Watchers Count472
Fork Count4.6k
Commits Count12.5k
Has Issues Enabled
Issues Count5014
Issue Open Count632
Pull Requests Count2300
Pull Requests Open Count70
Pull Requests Close Count955
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

.. image:: http://docs.celeryproject.org/en/latest/_images/celery-banner-small.png, build-status, coverage, license, wheel, pyversion, pyimp, ocbackerbadge, ocsponsorbadge, :Version: 4.4.0 (cliffs)
:Web: http://celeryproject.org/
:Download: https://pypi.org/project/celery/
:Source: https://github.com/celery/celery/
:Keywords: task, queue, job, async, rabbitmq, amqp, redis,
python, distributed, actors

Donations

This project relies on your generous donations.

If you are using Celery to create a commercial product, please consider becoming our backer_ or our sponsor_ to ensure Celery's future.

.. _backer: https://opencollective.com/celery#backer
.. _sponsor: https://opencollective.com/celery#sponsor

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of celery and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more. <https://tidelift.com/subscription/pkg/pypi-celery?utm_source=pypi-celery&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>_

What's a Task Queue?

Task queues are used as a mechanism to distribute work across threads or
machines.

A task queue's input is a unit of work, called a task, dedicated worker
processes then constantly monitor the queue for new work to perform.

Celery communicates via messages, usually using a broker
to mediate between clients and workers. To initiate a task a client puts a
message on the queue, the broker then delivers the message to a worker.

A Celery system can consist of multiple workers and brokers, giving way
to high availability and horizontal scaling.

Celery is written in Python, but the protocol can be implemented in any
language. In addition to Python there's node-celery_ for Node.js,
a PHP client_ and gocelery_ for golang.

Language interoperability can also be achieved by using webhooks
in such a way that the client enqueues an URL to be requested by a worker.

.. _node-celery: https://github.com/mher/node-celery
.. _PHP client: https://github.com/gjedeer/celery-php
.. _gocelery: https://github.com/gocelery/gocelery

What do I need?

Celery version 4.4.0 runs on,

  • Python (2.7, 3.8, 3.5, 3.6, 3.7)
  • PyPy2.7 (7.2)
  • PyPy3.5 (7.1)
  • PyPy3.6 (7.6)

4.x.x is the last version to support Python 2.7,
and from the next major version (Celery 5.x) Python 3.6 or newer is required.

If you're running an older version of Python, you need to be running
an older version of Celery:

  • Python 2.6: Celery series 3.1 or earlier.
  • Python 2.5: Celery series 3.0 or earlier.
  • Python 2.4 was Celery series 2.2 or earlier.

Celery is a project with minimal funding,
so we don't support Microsoft Windows.
Please don't open any issues related to that platform.

Celery is usually used with a message broker to send and receive messages.
The RabbitMQ, Redis transports are feature complete,
but there's also experimental support for a myriad of other solutions, including
using SQLite for local development.

Celery can run on a single machine, on multiple machines, or even
across datacenters.

Get Started

If this is the first time you're trying to use Celery, or you're
new to Celery 4.4 coming from previous versions then you should read our
getting started tutorials:

  • First steps with Celery_

    Tutorial teaching you the bare minimum needed to get started with Celery.

  • Next steps_

    A more complete overview, showing more features.

.. _First steps with Celery:
http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html

.. _Next steps:
http://docs.celeryproject.org/en/latest/getting-started/next-steps.html

Celery is...

  • Simple

    Celery is easy to use and maintain, and does not need configuration files.

    It has an active, friendly community you can talk to for support,
    like at our mailing-list_, or the IRC channel.

    Here's one of the simplest applications you can make::

      from celery import Celery
    
      app = Celery('hello', broker='amqp://guest@localhost//')
    
      @app.task
      def hello():
          return 'hello world'
    
  • Highly Available

    Workers and clients will automatically retry in the event
    of connection loss or failure, and some brokers support
    HA in way of Primary/Primary or Primary/Replica replication.

  • Fast

    A single Celery process can process millions of tasks a minute,
    with sub-millisecond round-trip latency (using RabbitMQ,
    py-librabbitmq, and optimized settings).

  • Flexible

    Almost every part of Celery can be extended or used on its own,
    Custom pool implementations, serializers, compression schemes, logging,
    schedulers, consumers, producers, broker transports, and much more.

It supports...

- **Message Transports**

    - RabbitMQ_, Redis_, Amazon SQS

- **Concurrency**

    - Prefork, Eventlet_, gevent_, single threaded (``solo``)

- **Result Stores**

    - AMQP, Redis
    - memcached
    - SQLAlchemy, Django ORM
    - Apache Cassandra, IronCache, Elasticsearch

- **Serialization**

    - *pickle*, *json*, *yaml*, *msgpack*.
    - *zlib*, *bzip2* compression.
    - Cryptographic message signing.

.. _Eventlet: http://eventlet.net/
.. _gevent: http://gevent.org/

.. _RabbitMQ: https://rabbitmq.com
.. _Redis: https://redis.io
.. _SQLAlchemy: http://sqlalchemy.org

Framework Integration

Celery is easy to integrate with web frameworks, some of which even have
integration packages:

+--------------------+------------------------+, `Django`_, not needed, +--------------------+------------------------+, `Pyramid`_, `pyramid_celery`_, +--------------------+------------------------+, `Pylons`_, `celery-pylons`_, +--------------------+------------------------+, `Flask`_, not needed, +--------------------+------------------------+, `web2py`_, `web2py-celery`_, +--------------------+------------------------+, `Tornado`_, `tornado-celery`_, +--------------------+------------------------+

The integration packages aren't strictly necessary, but they can make
development easier, and sometimes they add important hooks like closing
database connections at fork.

.. _Django: https://djangoproject.com/
.. _Pylons: http://pylonsproject.org/
.. _Flask: http://flask.pocoo.org/
.. _web2py: http://web2py.com/
.. _Bottle: https://bottlepy.org/
.. _Pyramid: http://docs.pylonsproject.org/en/latest/docs/pyramid.html
.. _pyramid_celery: https://pypi.org/project/pyramid_celery/
.. _celery-pylons: https://pypi.org/project/celery-pylons/
.. _web2py-celery: https://code.google.com/p/web2py-celery/
.. _Tornado: http://www.tornadoweb.org/
.. _tornado-celery: https://github.com/mher/tornado-celery/

.. _celery-documentation:

Documentation

The latest documentation_ is hosted at Read The Docs, containing user guides,
tutorials, and an API reference.

最新的中文文档托管在 https://www.celerycn.io/ 中,包含用户指南、教程、API接口等。

.. _latest documentation: http://docs.celeryproject.org/en/latest/

.. _celery-installation:

Installation

You can install Celery either via the Python Package Index (PyPI)
or from source.

To install using pip:

::

$ pip install -U Celery

.. _bundles:

Bundles

Celery also defines a group of bundles that can be used
to install Celery and the dependencies for a given feature.

You can specify these in your requirements or on the pip
command-line by using brackets. Multiple bundles can be specified by
separating them by commas.

::

$ pip install "celery[librabbitmq]"

$ pip install "celery[librabbitmq,redis,auth,msgpack]"

The following bundles are available:

Serializers


:``celery[auth]``:
    for using the ``auth`` security serializer.

:``celery[msgpack]``:
    for using the msgpack serializer.

:``celery[yaml]``:
    for using the yaml serializer.

Concurrency

:celery[eventlet]:
for using the eventlet pool.

:celery[gevent]:
for using the gevent pool.

Transports and Backends


:``celery[librabbitmq]``:
    for using the librabbitmq C library.

:``celery[redis]``:
    for using Redis as a message transport or as a result backend.

:``celery[sqs]``:
    for using Amazon SQS as a message transport.

:``celery[tblib``]:
    for using the ``task_remote_tracebacks`` feature.

:``celery[memcache]``:
    for using Memcached as a result backend (using ``pylibmc``)

:``celery[pymemcache]``:
    for using Memcached as a result backend (pure-Python implementation).

:``celery[cassandra]``:
    for using Apache Cassandra as a result backend with DataStax driver.

:``celery[azureblockblob]``:
    for using Azure Storage as a result backend (using ``azure-storage``)

:``celery[s3]``:
    for using S3 Storage as a result backend.

:``celery[couchbase]``:
    for using Couchbase as a result backend.

:``celery[arangodb]``:
    for using ArangoDB as a result backend.

:``celery[elasticsearch]``:
    for using Elasticsearch as a result backend.

:``celery[riak]``:
    for using Riak as a result backend.

:``celery[cosmosdbsql]``:
    for using Azure Cosmos DB as a result backend (using ``pydocumentdb``)

:``celery[zookeeper]``:
    for using Zookeeper as a message transport.

:``celery[sqlalchemy]``:
    for using SQLAlchemy as a result backend (*supported*).

:``celery[pyro]``:
    for using the Pyro4 message transport (*experimental*).

:``celery[slmq]``:
    for using the SoftLayer Message Queue transport (*experimental*).

:``celery[consul]``:
    for using the Consul.io Key/Value store as a message transport or result backend (*experimental*).

:``celery[django]``:
    specifies the lowest version possible for Django support.

    You should probably not use this in your requirements, it's here
    for informational purposes only.


.. _celery-installing-from-source:

Downloading and installing from source
--------------------------------------

Download the latest version of Celery from PyPI:

https://pypi.org/project/celery/

You can install it by doing the following,:

::


    $ tar xvfz celery-0.0.0.tar.gz
    $ cd celery-0.0.0
    $ python setup.py build
    # python setup.py install

The last command must be executed as a privileged user if
you aren't currently using a virtualenv.

.. _celery-installing-from-git:

Using the development version
-----------------------------

With pip
~~~~~~~~

The Celery development version also requires the development
versions of ``kombu``, ``amqp``, ``billiard``, and ``vine``.

You can install the latest snapshot of these using the following
pip commands:

::


    $ pip install https://github.com/celery/celery/zipball/master#egg=celery
    $ pip install https://github.com/celery/billiard/zipball/master#egg=billiard
    $ pip install https://github.com/celery/py-amqp/zipball/master#egg=amqp
    $ pip install https://github.com/celery/kombu/zipball/master#egg=kombu
    $ pip install https://github.com/celery/vine/zipball/master#egg=vine

With git
~~~~~~~~

Please see the Contributing section.

.. _getting-help:

Getting Help
============

.. _mailing-list:

Mailing list
------------

For discussions about the usage, development, and future of Celery,
please join the `celery-users`_ mailing list.

.. _`celery-users`: https://groups.google.com/group/celery-users/

.. _irc-channel:

IRC
---

Come chat with us on IRC. The **#celery** channel is located at the `Freenode`_
network.

.. _`Freenode`: https://freenode.net

.. _bug-tracker:

Bug tracker
===========

If you have any suggestions, bug reports, or annoyances please report them
to our issue tracker at https://github.com/celery/celery/issues/

.. _wiki:

Wiki
====

https://github.com/celery/celery/wiki

Credits
=======

.. _contributing-short:

Contributors
------------

This project exists thanks to all the people who contribute. Development of
`celery` happens at GitHub: https://github.com/celery/celery

You're highly encouraged to participate in the development
of `celery`. If you don't like GitHub (for some reason) you're welcome
to send regular patches.

Be sure to also read the `Contributing to Celery`_ section in the
documentation.

.. _`Contributing to Celery`:
    http://docs.celeryproject.org/en/master/contributing.html, oc-contributors, .., oc-contributors, image:: https://opencollective.com/celery/contributors.svg?width=890&button=false
    :target: https://github.com/celery/celery/graphs/contributors

Backers
-------

Thank you to all our backers! ? [`Become a backer`_]

.. _`Become a backer`: https://opencollective.com/celery#backer, oc-backers, .., oc-backers, image:: https://opencollective.com/celery/backers.svg?width=890
    :target: https://opencollective.com/celery#backers

Sponsors
--------

Support this project by becoming a sponsor. Your logo will show up here with a
link to your website. [`Become a sponsor`_]

.. _`Become a sponsor`: https://opencollective.com/celery#sponsor, oc-sponsors, .., oc-sponsors, image:: https://opencollective.com/celery/sponsor/0/avatar.svg
    :target: https://opencollective.com/celery/sponsor/0/website

.. _license:

License
=======

This software is licensed under the `New BSD License`. See the ``LICENSE``
file in the top distribution directory for the full license text.

.. # vim: syntax=rst expandtab tabstop=4 shiftwidth=4 shiftround

.., build-status, image:: https://secure.travis-ci.org/celery/celery.png?branch=master
    :alt: Build status
    :target: https://travis-ci.org/celery/celery

.., coverage, image:: https://codecov.io/github/celery/celery/coverage.svg?branch=master
    :target: https://codecov.io/github/celery/celery?branch=master

.., license, image:: https://img.shields.io/pypi/l/celery.svg
    :alt: BSD License
    :target: https://opensource.org/licenses/BSD-3-Clause

.., wheel, image:: https://img.shields.io/pypi/wheel/celery.svg
    :alt: Celery can be installed via wheel
    :target: https://pypi.org/project/celery/

.., pyversion, image:: https://img.shields.io/pypi/pyversions/celery.svg
    :alt: Supported Python versions.
    :target: https://pypi.org/project/celery/

.., pyimp, image:: https://img.shields.io/pypi/implementation/celery.svg
    :alt: Support Python implementations.
    :target: https://pypi.org/project/celery/

.., ocbackerbadge, image:: https://opencollective.com/celery/backers/badge.svg
    :alt: Backers on Open Collective
    :target: #backers

.., ocsponsorbadge, image:: https://opencollective.com/celery/sponsors/badge.svg
    :alt: Sponsors on Open Collective
    :target: #sponsors

.., downloads, image:: https://pepy.tech/badge/celery
    :alt: Downloads
    :target: https://pepy.tech/project/celery
To the top