【问题标题】:Celery Crontab in not Picking the tasksCelery Crontab 在不挑选任务
【发布时间】:2021-10-02 23:24:11
【问题描述】:

我在 celery beat 时间表中每 1 分钟添加一次 crontab。迁移也做得很好。我可以错过这段代码中的任何内容吗?crontab 格式是否正确。
提前致谢 。 crontab 几分钟就可以了

settings.py
INSTALLED_APPS = [
'app1',
'django_celery_beat',
]
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'

from celery.schedules import crontab

CELERY_BEAT_SCHEDULE = {
'task-second': {
    'task': 'app1.tasks.elast',
    'schedule': crontab(minute=1),
}
}   

celery.py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
app = Celery('proj')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()


__init__.py
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ('celery_app',)

tasks.py
from __future__ import absolute_import, unicode_literals

from proj.celery import app

@app.task
def elast():
    print("start")
    return "Exceuting after 1 minute"

celery beat worker:
celery -A proj beat --loglevel=debug --scheduler django_celery_beat.schedulers:DatabaseScheduler

logformat :
celery beat v5.1.2 (sun-harmonics) is starting.

[2021-07-27 11:07:00,894: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2021-07-27 11:07:00,916: DEBUG/MainProcess] beat: Waking up in 5.00 seconds.
[2021-07-27 11:07:05,931: DEBUG/MainProcess] beat: Synchronizing schedule...
[2021-07-27 11:07:05,932: DEBUG/MainProcess] Writing entries...

【问题讨论】:

  • 你也在开工吗?您需要有一个节拍调度程序进程和工作进程。
  • 是的,我也添加了工人,它可以正常用于其他任务

标签: python django rabbitmq celery django-celery-beat


【解决方案1】:

改变

*'schedule': crontab(minute=1),*

进入

'schedule': crontab(minute='*/1'),

它应该可以工作。

【讨论】:

    猜你喜欢
    • 2019-02-08
    • 2019-05-17
    • 2013-04-20
    • 1970-01-01
    • 2018-01-02
    • 2017-03-12
    • 1970-01-01
    • 2020-09-13
    • 2019-12-26
    相关资源
    最近更新 更多