import djcelery from datetime import timedelta djcelery.setup_loader() CELERY_IMPORTS=( 'apptest.tasks', ) CELERY_QUEUES={ #定时任务队列配置 'beat_tasks':{ 'exchange':'beat_tasks', 'exchange_type':'direct', 'binding_key':'beat_tasks' }, # 普通任务队列配置 'work_queue': { 'exchange': 'work_queue', 'exchange_type': 'direct', 'binding_key': 'work_queue' } } CELERY_DEFAULT_QUEUE = 'work_queue' # celery 配置 # 有些情况下防止死锁 CELERYD_FORCE_EXECV = True # 设置并发的worker数量 CELERYD_CONCURRENCY = 4 # 允许重试 CELERY_ACKS_LATE = True # 每个worker最多允许执行100个任务被销毁,可以防止内存泄漏 CELERY_MAX_TASKS_PER_CHILD = 100 # 单个任务的最大运行时间 CELERYD_TASK_TIME_LIMIT = 12 * 30 CELERYBEAT_SCHEDULE = { 'tasks1': { 'task':'course-task', 'schedule':timedelta(seconds=5), 'args':(2,8), 'options':{ 'queue':'beat_tasks' } } #每天10点执行 # 'task2': # { # 'task': 'celery_app.task2.mutiply', # 'schedule': crontab(hour=15,minute=15), # 'args': (4, 5) # } }
但是日志没有运行到beat
celery beat v3.1.26.post2 (Cipater) is starting.
__ - ... __ - _
Configuration ->
. broker -> amqp://guest:**@localhost:5672//
. loader -> celery.loaders.default.Loader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@%INFO
. maxinterval -> now (0s)
[2021-03-27 15:48:48,978: INFO/MainProcess] beat: Starting...