我在芹菜节拍时间表中每1分钟添加一次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...
变化
*'schedule': crontab(minute=1),*
到
'schedule': crontab(minute='*/1'),
应该可以。