【问题标题】:celery recurring task not executing芹菜重复任务未执行
【发布时间】:2013-12-16 18:42:59
【问题描述】:

我的周期性任务永远不会执行。我错过了什么?我正在运行 RabbitMQ 服务。我也有花跑,芹菜工人出现在那里。

令人沮丧的是,有大量关于如何在 Django 中使用 celery 的示例,但其中大部分是旧版本,我认为不适用于最新版本。

芹菜.py

from __future__ import absolute_import

import os

from celery import Celery

from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'solar_secured.settings')

app = Celery('solar_secured', broker='amqp://guest@localhost//')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

tasks.py

from asset_monitor.process_raw import parse_rawdata

from datetime import timedelta
from celery.task import periodic_task

@periodic_task(run_every=timedelta(minutes=5))
def parse_raw():
    parse_rawdata()

开始芹菜工人

C:\dev\solar_secured>manage.py celeryd
C:\Python27\lib\site-packages\celery-3.1.6-py2.7.egg\celery\apps\worker.py:159:
CDeprecationWarning:
Starting from version 3.2 Celery will refuse to accept pickle by default.

The pickle serializer is a security concern as it may give attackers
the ability to execute any command.  It's important to secure
your broker from unauthorized access when using pickle, so we think
that enabling pickle should require a deliberate action and not be
the default choice.

If you depend on pickle then you should set a setting to disable this
warning and to be sure that everything will continue working
when you upgrade to Celery 3.2::

    CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']

You must only enable the serializers that you will actually use.


  warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))

[2013-12-16 11:26:19,302: WARNING/MainProcess] C:\Python27\lib\site-packages\cel
ery-3.1.6-py2.7.egg\celery\apps\worker.py:159: CDeprecationWarning:
Starting from version 3.2 Celery will refuse to accept pickle by default.

The pickle serializer is a security concern as it may give attackers
the ability to execute any command.  It's important to secure
your broker from unauthorized access when using pickle, so we think
that enabling pickle should require a deliberate action and not be
the default choice.

If you depend on pickle then you should set a setting to disable this
warning and to be sure that everything will continue working
when you upgrade to Celery 3.2::

    CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']

You must only enable the serializers that you will actually use.


  warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))


 -------------- celery@DjangoDev v3.1.6 (Cipater)
---- **** -----
--- * ***  * -- Windows-2008ServerR2-6.1.7601-SP1
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> broker:      amqp://guest@localhost:5672//
- ** ---------- .> app:         solar_secured:0x2cd4b00
- ** ---------- .> concurrency: 8 (prefork)
- *** --- * --- .> events:      OFF (enable -E to monitor this worker)
-- ******* ----
--- ***** ----- [queues]
 -------------- .> celery           exchange=celery(direct) key=celery


C:\Python27\lib\site-packages\celery-3.1.6-py2.7.egg\celery\fixups\django.py:224
: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setti
ng in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-12-16 11:26:20,512: WARNING/MainProcess] C:\Python27\lib\site-packages\cel
ery-3.1.6-py2.7.egg\celery\fixups\django.py:224: UserWarning: Using settings.DEB
UG leads to a memory leak, never use this setting in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-12-16 11:26:20,512: WARNING/MainProcess] celery@DjangoDev ready.

开始芹菜节拍

C:\dev\solar_secured>manage.py celery beat
celery beat v3.1.6 (Cipater) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> amqp://guest@localhost:5672//
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@%INFO
    . maxinterval -> now (0s)
[2013-12-16 14:18:48,206: INFO/MainProcess] beat: Starting...

【问题讨论】:

    标签: python django rabbitmq celery


    【解决方案1】:

    您必须使用调度程序来执行periodic tasks。您可以使用默认调度程序 Celery 的 Beat。使用以下命令使用beat python manage.py celery worker -B

    【讨论】:

    • 当我尝试启动 celery beat 时,由于文件 celerybeat.pid 的存在,它错误地说进程已经在运行。当我删除该文件并执行 manage.py celery beat 时,我的作业开始按计划运行。您在上面使用 -B 选项使用的格式不适用于最新版本的 celery。
    猜你喜欢
    • 2017-04-11
    • 2021-12-16
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    相关资源
    最近更新 更多