【Python】django_celery_beat 无限创建定时任务该如何解决?
django_celery_beat 无限创建定时任务该如何解决?
调度CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
任务
from __future__ import absolute_import, unicode_literals
from celery import shared_task
@shared_task
def add(x, y):
return x + y
django-admin 配置周期性任务
启动beat后无限创建任务# celery -A CDNAdmin beat --loglevel=debug
celery beat v4.1.0 (latentcall) is starting.
__ - ... __ - _
LocalTime -> 2018-04-23 17:01:12
Configuration ->
. broker -> redis://127.0.0.1:6379/1
. loader -> celery.loaders.app.AppLoader
. scheduler -> django_celery_beat.schedulers.DatabaseScheduler
. logfile -> [stderr]@%DEBUG
. maxinterval -> 5.00 seconds (5s)
[2018-04-23 17:01:12,014: DEBUG/MainProcess] Setting default socket timeout to 30
[2018-04-23 17:01:12,015: INFO/MainProcess] beat: Starting...
[2018-04-23 17:01:12,015: DEBUG/MainProcess] DatabaseScheduler: initial read
[2018-04-23 17:01:12,015: INFO/MainProcess] Writing entries...
[2018-04-23 17:01:12,021: DEBUG/MainProcess] DatabaseScheduler: Fetching database schedule
[2018-04-23 17:01:12,038: DEBUG/MainProcess] Current schedule:
<ModelEntry: add netcut.tasks.add(*[2, 2], **{}) <freq: 5.00 minutes>>
<ModelEntry: celery.backend_cleanup celery.backend_cleanup(*[], **{}) <crontab: 0 4 * * * (m/h/d/dM/MY)>>
[2018-04-23 17:01:12,065: DEBUG/MainProcess] beat: Ticking with max interval->5.00 seconds
[2018-04-23 17:01:12,085: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,114: DEBUG/MainProcess] beat: Synchronizing schedule...
[2018-04-23 17:01:12,114: INFO/MainProcess] Writing entries...
[2018-04-23 17:01:12,129: DEBUG/MainProcess] netcut.tasks.add sent. id->d2179952-9d87-4ef0-8d54-7796f9816d9a
[2018-04-23 17:01:12,131: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,133: DEBUG/MainProcess] netcut.tasks.add sent. id->d8651734-6481-4897-95f6-33da66df6de3
[2018-04-23 17:01:12,136: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,138: DEBUG/MainProcess] netcut.tasks.add sent. id->a6f5407a-f7d9-4319-a9ec-6d5dc207b217
[2018-04-23 17:01:12,140: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,142: DEBUG/MainProcess] netcut.tasks.add sent. id->85d71d15-8be4-4582-b80b-afa396159cba
[2018-04-23 17:01:12,144: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,146: DEBUG/MainProcess] netcut.tasks.add sent. id->d099f9ba-6fc3-4230-9b1c-2300ac43a315
[2018-04-23 17:01:12,148: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,150: DEBUG/MainProcess] netcut.tasks.add sent. id->49d21492-6547-440c-89bb-1ee7f541edfc
[2018-04-23 17:01:12,152: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,155: DEBUG/MainProcess] netcut.tasks.add sent. id->3fe360c0-d3dc-47d8-b0a3-4ce197f545db
[2018-04-23 17:01:12,157: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,159: DEBUG/MainProcess] netcut.tasks.add sent. id->92e38cfb-2838-4d56-9dc7-efaa6635ce05
[2018-04-23 17:01:12,162: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,164: DEBUG/MainProcess] netcut.tasks.add sent. id->8986f037-e7c0-4386-90d5-1ad8c685befc
[2018-04-23 17:01:12,167: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
[2018-04-23 17:01:12,169: DEBUG/MainProcess] netcut.tasks.add sent. id->4ccc0c70-d7b0-4153-9c1b-a399dc8a9402
[2018-04-23 17:01:12,171: INFO/MainProcess] Scheduler: Sending due task add (netcut.tasks.add)
回答
找到问题了,和celery 时区有关系。
setting增加如下配置
CELERY_ENABLE_UTC = False
妈耶 折腾我一晚上了 等我到家远程试试
我想请问一下,我的beat启动之后,通过接口写入任务不执行是什么原因呢?
以上是 【Python】django_celery_beat 无限创建定时任务该如何解决? 的全部内容, 来源链接: utcz.com/a/79654.html