Celery 弃用时间表¶
Celery Deprecation Time-line
5.0 版移除内容¶
Removals for version 5.0
旧版任务 API¶
Old Task API
兼容任务模块¶
Compat Task Modules
模块
celery.decorators
将被移除: 这意味着你需要将如下代码:from celery.decorators import task
修改为:
from celery import task
模块
celery.task
将被移除 这意味着你应该将如下代码:from celery.task import task
修改为:
from celery import shared_task
—— 以及:
from celery import task
修改为:
from celery import shared_task
—— 还有:
from celery.task import Task
修改为:
from celery import Task
请注意,新的 Task
类不再使用 classmethod()
修饰以下方法:
delay
apply_async
retry
apply
AsyncResult
subtask
这也意味着你不能再直接通过类调用这些方法,而是需要先实例化任务:
>>> MyTask.delay() # 不再可用
>>> MyTask().delay() # 正确用法!
- Module
celery.decorators
will be removed: This means you need to change:
from celery.decorators import task
Into:
from celery import task
- Module
- Module
celery.task
will be removed This means you should change:
from celery.task import task
into:
from celery import shared_task
-- and:
from celery import task
into:
from celery import shared_task
-- and:
from celery.task import Task
into:
from celery import Task
- Module
Note that the new Task
class no longer
uses classmethod()
for these methods:
delay
apply_async
retry
apply
AsyncResult
subtask
This also means that you can't call these methods directly on the class, but have to instantiate the task first:
>>> MyTask.delay() # NO LONGER WORKS
>>> MyTask().delay() # WORKS!
任务属性¶
Task attributes
以下任务属性已弃用,必须通过 task_routes
来设置:
queue
exchange
exchange_type
routing_key
delivery_mode
priority
The task attributes:
queue
exchange
exchange_type
routing_key
delivery_mode
priority
is deprecated and must be set by task_routes
instead.
待移除模块¶
Modules to Remove
celery.execute
此模块仅包含
send_task
:应改为使用app.send_task
。celery.decorators
参见 兼容任务模块
celery.log
改为使用
app.log
celery.messaging
改为使用
app.amqp
celery.registry
改为使用
celery.app.registry
celery.task.control
改为使用
app.control
celery.task.schedules
改为使用
celery.schedules
celery.task.chords
改为使用
celery.chord()
celery.execute
This module only contains
send_task
: this must be replaced withapp.send_task
instead.celery.decorators
See 兼容任务模块
celery.log
Use
app.log
instead.celery.messaging
Use
app.amqp
instead.celery.registry
Use
celery.app.registry
instead.celery.task.control
Use
app.control
instead.celery.task.schedules
Use
celery.schedules
instead.celery.task.chords
Use
celery.chord()
instead.
设置¶
Settings
BROKER
设置¶
BROKER
Settings
Setting name |
Replace with |
---|---|
|
|
|
|
|
|
|
|
|
REDIS
结果后端设置¶
REDIS
Result Backend Settings
Setting name |
Replace with |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Task_sent 信号¶
Task_sent signal
task_sent
信号将在 4.0 版本中移除。
请改用 before_task_publish
和 after_task_publish
信号。
The task_sent
signal will be removed in version 4.0.
Please use the before_task_publish
and after_task_publish
signals instead.
结果¶
Result
适用于:AsyncResult
,
EagerResult
:
Result.wait()
->Result.get()
Result.task_id()
->Result.id
Result.status
->Result.state
Apply to: AsyncResult
, EagerResult
:
Result.wait()
->Result.get()
Result.task_id()
->Result.id
Result.status
->Result.state
.
设置¶
Settings
Setting name |
Replace with |
---|---|
|
2.0 版移除内容¶
Removals for version 2.0
以下配置项将被移除:
配置项名称 |
替代项 |
---|---|
CELERY_AMQP_CONSUMER_QUEUES |
task_queues |
CELERY_AMQP_CONSUMER_QUEUES |
task_queues |
CELERY_AMQP_EXCHANGE |
task_default_exchange |
CELERY_AMQP_EXCHANGE_TYPE |
task_default_exchange_type |
CELERY_AMQP_CONSUMER_ROUTING_KEY |
task_queues |
CELERY_AMQP_PUBLISHER_ROUTING_KEY |
task_default_routing_key |
未包含类名的
CELERY_LOADER
定义例如:celery.loaders.default,必须包含类名: celery.loaders.default.Loader
TaskSet.run()
。请改为使用celery.task.base.TaskSet.apply_async()
。
The following settings will be removed:
Setting name |
Replace with |
---|---|
CELERY_AMQP_CONSUMER_QUEUES |
task_queues |
CELERY_AMQP_CONSUMER_QUEUES |
task_queues |
CELERY_AMQP_EXCHANGE |
task_default_exchange |
CELERY_AMQP_EXCHANGE_TYPE |
task_default_exchange_type |
CELERY_AMQP_CONSUMER_ROUTING_KEY |
task_queues |
CELERY_AMQP_PUBLISHER_ROUTING_KEY |
task_default_routing_key |
CELERY_LOADER
definitions without class name.For example,, celery.loaders.default, needs to include the class name: celery.loaders.default.Loader.
TaskSet.run()
. Usecelery.task.base.TaskSet.apply_async()
instead.