Huey; Не запускает задачи в одном Django приложении - PullRequest
0 голосов
/ 18 марта 2020

У меня есть приложение под названием «Билеты», оно находится в файле настроек, может быть правильно импортировано.

INSTALLED_APPS = [
... 
"huey.contrib.djhuey",
"core",
"telefon",
"termine",
"tickets",
...
]

Я запускаю Huey для фоновых задач, и он запускает все задачи в двух других приложениях, но не в «тикетах» приложения. Вот модуль "помощники" в заявке приложения:

from huey import crontab
from huey.contrib.djhuey import db_periodic_task, periodic_task

@periodic_task(crontab(minute="*/1"))
def checkForRunningHuey():
    logger.debug("Huey did run at {pendulum.now()}")


@db_periodic_task(crontab(minute="*/5"))
def getKissTickets():
    site_settings = Setting.load()
    if not site_settings.last_update_tickets:
        soy, now = getThisYear
        site_settings.last_update_tickets = soy
        site_settings.save()
    site_settings = Setting.load()
    ...

А вот мой Конфигурация Huey:

HUEY = {
    "huey_class": "huey.RedisHuey",  # Huey implementation to use.
    "name": "Huey",  # Use db name for huey.
    "results": False,  # Store return values of tasks.
    "store_none": False,  # If a task returns None, do not save to results.
    "immediate": False,  # If DEBUG=True, run synchronously.
    "utc": True,  # Use UTC for all times internally.
    "blocking": True,  # Perform blocking pop rather than poll Redis.
    "connection": {
        "host": "192.168.x.xxx",
        "port": 6379,
        "db": 0,
        "connection_pool": None,  # Definitely you should use pooling!
        "read_timeout": 1,  # If not polling (blocking pop), use timeout.
        "url": None,  # Allow Redis config via a DSN.
    },
}

А вот вывод manage.py run_huey:

$ python manage.py run_huey --huey-verbose
[2020-03-18 14:17:08,249] INFO:huey.consumer:MainThread:Huey consumer started with 1 thread, PID 3100 at 2020-03-18 13:17:08.249881
[2020-03-18 14:17:08,249] INFO:huey.consumer:MainThread:Scheduler runs every 1 second(s).
[2020-03-18 14:17:08,251] INFO:huey.consumer:MainThread:Periodic tasks are enabled.
[2020-03-18 14:17:08,252] INFO:huey.consumer:MainThread:The following commands are available:
[2020-03-18 14:17:08,368] DEBUG:huey.consumer.Scheduler:Scheduler:Checking periodic tasks
[2020-03-18 14:17:08,368] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.8815112113952637
[2020-03-18 14:17:09,288] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.9611930847167969
[2020-03-18 14:17:10,316] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.9331824779510498
[2020-03-18 14:17:11,296] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.9533252716064453
[2020-03-18 14:17:12,330] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.9188826084136963
[2020-03-18 14:17:13,311] DEBUG:huey.consumer.Scheduler:Scheduler:Sleeping for 0.9387216567993164

1 Ответ

1 голос
/ 03 апреля 2020

Когда потребитель запускается, ему необходимо импортировать все модули, для которых определены задачи, иначе они не будут выбраны. Команда управления run_huey автоматически обнаружит любые имена модулей tasks.py, используя autodiscover_modules("tasks").

. Чтобы выбрать периодические задачи c, вам необходимо определить их в tasks.py или пусть tasks.py импортирует модуль, в котором они определены.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...