структура файла
proj/proj/
celery.py
(and other files)
/sitesettings/
tasks.py
(and other files)
celery.py
app = Celery('mooncake',broker_url = 'amqp://')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
sitesettings / tasks.py
from __future__ import absolute_import, unicode_literals
from comma.models import Post
from mooncake.celery import app
app.conf.beat_schedule = {
'every-5-seconds': {
'task': 'sitesettings.tasks.statisticsTag',
'schedule': 5.0,
'args': ()
},
}
@app.task
def statisticsTag():
print(Post.objects.all()[0])
и запустите его с
celery -A proj beat -l info
выводится с
[2019-02-22 18:21:08,346: INFO/MainProcess] Scheduler: Sending due task every-5-seconds (sitesettings.tasks.statisticsTag)
, но без дальнейшего вывода.Я пытался написать его в proj / celery.py, но он не может работать, потому что мне нужно импортировать из другого приложения, он завершается с ошибкой «приложение не загружено».Так что мне делать?