Celery-beat处理程序on_after_configure / finalize无法与add_periodic_task一起使用

时间:2019-11-03 02:26:20

标签: django-celery celerybeat

我正在尝试使用Celery及其Celery节拍功能来安排任务。我正在尝试使用on_after_configure / finalize用芹菜拍打成一个“ hello world”,但它没有显示任何日志。

我尝试将项目和芹菜的时区设置为UTC。 我尝试使用@shared_task装饰器和其他调整 尽管如此,我还是设法使用@periodic_task装饰器安排了任务。 您能帮我解决这个处理程序/信号问题吗? 谢谢

settings.py

class TimeseriesSerializer(serializers.ModelSerializer):

    venue = VenueNameSerializer(source="venue_id",many=False, read_only=True)
    year = serializers.TimeField(read_only=True)
    count = serializers.IntegerField(read_only=True)

    class Meta:
        model = Tracking
        fields = ("venue",
                  "year",
                  "count")


class TimeseriesSerializer(serializers.Serializer): <-- here is another try but doesnt work serializers.Serializer

    venue_id = VenueNameSerializer(many=False, read_only=True)
    year = serializers.TimeField(read_only=True)
    count = serializers.IntegerField(read_only=True)

celery.py(不工作-不在日志中显示任务)

TIME_ZONE = 'UTC'
USE_TZ = True
...
CELERY_RESULT_BACKEND = 'django-db'
CELERY_CACHE_BACKEND = 'django-cache'
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True

celery.py(工作中)

from __future__ import absolute_import, unicode_literals
from celery import Celery
from celery.task import periodic_task

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','monkyroproject.settings')

celeryapp2 = Celery('monkyroproject',
             broker='amqp://',
             backend='amqp://',
             include=['monkyroproject.tasks'])

celeryapp2.conf.update(
    result_expires=3600,
)

if __name__ == '__main__':
    celeryapp2.start()

@celeryapp2.task
def test1():
    print("Hello World")
    return('Test1 well executed')

@celeryapp2.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
    sender.add_periodic_task(10.0,test1.s(),name = 'iterate every 10 sec')

我希望更改时间表并显示正在发送的任务。

from __future__ import absolute_import, unicode_literals
from celery import Celery
from celery.schedules import crontab
from celery.task import periodic_task

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','monkyroproject.settings')

celeryapp2 = Celery('monkyroproject',
             broker='amqp://',
             backend='amqp://',
             include=['monkyroproject.tasks'])

celeryapp2.conf.update(
    result_expires=3600,
)

if __name__ == '__main__':
    celeryapp2.start()

@periodic_task(run_every=crontab(minute='*'),name='test_beat',ignore_result=False)
def test_beat():
    print('Hello World')
    return 'Test Beat well done'

它只告诉我这个

[2019-11-03 03:19:58,753: INFO/MainProcess] beat: Starting...
[2019-11-03 03:19:58,762: INFO/MainProcess] Writing entries...
[2019-11-03 03:20:00,328: INFO/MainProcess] DatabaseScheduler: Schedule changed.
[2019-11-03 03:20:00,330: INFO/MainProcess] Writing entries...
[2019-11-03 03:20:05,430: INFO/MainProcess] Writing entries...
[2019-11-03 03:21:00,029: INFO/MainProcess] Scheduler: Sending due task test_beat (test_beat)
[2019-11-03 03:21:00,042: WARNING/MainProcess] c:\users\idriss\django_projects\monkyroproject\virtual002\lib\site-packages\celery\backends\amqp.py:67: CPendingDeprecationWarning:
    The AMQP result backend is scheduled for deprecation in     version 4.0 and removal in version v5.0.     Please use RPC backend or a persistent backend.

  alternative='Please use RPC backend or a persistent backend.')
[2019-11-03 03:22:00,005: INFO/MainProcess] Scheduler: Sending due task test_beat (test_beat)
[2019-11-03 03:23:00,002: INFO/MainProcess] Scheduler: Sending due task test_beat (test_beat)

0 个答案:

没有答案