以下是我的settings.py
的摘录CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
import djcelery
from celery.schedules import crontab
djcelery.setup_loader()
CELERY_IMPORTS = ("app.some.tasks",)
CELERYBEAT_SCHEDULE = {
"send_mail": {
"task": "app.some.tasks.send_mail",
"schedule": timedelta(seconds=30),
},
}
当send_mail
任务运行时,其他任务无法运行(忽略,从celeryd日志中看不到)
[2015-08-01 23:39:36,155: INFO/MainProcess] start send_mails task.
[2015-08-01 23:39:36,185: INFO/MainProcess] finish send_mails task.
[2015-08-01 23:40:04,643: INFO/MainProcess] start send_mails task.
[2015-08-01 23:40:04,666: INFO/MainProcess] finish send_mails task.
[2015-08-01 23:40:06,163: INFO/MainProcess] start send_mails task.
[2015-08-01 23:40:06,205: INFO/MainProcess] finish send_mails task.
[2015-08-01 23:40:34,657: INFO/MainProcess] start send_mails task.
[2015-08-01 23:40:34,684: INFO/MainProcess] finish send_mails task.
但如果我在这30秒间隔内执行另一项任务,那么它实际上就会运行。
send_mail
任务
@task
def send_mail():
log.info( u'start send_mails task.' )
from django.core import management
management.call_command('send_mail')
log.info( u'finish send_mails task.' )
send_mail
是来自mailer
包的命令。
Celeryd执行如下
celeryd --settings=settings --beat --concurrency=8