休伊;一个 Django 应用程序中没有 运行 个任务
Huey; Doesn't run tasks in one Django App
我有一个应用叫"tickets",它在设置文件里,可以正确导入。
INSTALLED_APPS = [
...
"huey.contrib.djhuey",
"core",
"telefon",
"termine",
"tickets",
...
]
我 运行ning Huey 负责后台任务,它 运行 在其他两个应用程序中执行所有任务,只是不在应用程序 "tickets" 中。这是应用程序门票中的模块 "helpers":
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
当消费者是 运行 时,它需要导入定义任务的所有模块,否则它们不会被拾取。 run_huey
管理命令将使用 autodiscover_modules("tasks")
.
自动发现任何模块名称 tasks.py
为了让您的周期性任务被拾取,您需要在 tasks.py
中定义它们,或者让 tasks.py
导入定义它们的模块。
我有一个应用叫"tickets",它在设置文件里,可以正确导入。
INSTALLED_APPS = [
...
"huey.contrib.djhuey",
"core",
"telefon",
"termine",
"tickets",
...
]
我 运行ning Huey 负责后台任务,它 运行 在其他两个应用程序中执行所有任务,只是不在应用程序 "tickets" 中。这是应用程序门票中的模块 "helpers":
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
当消费者是 运行 时,它需要导入定义任务的所有模块,否则它们不会被拾取。 run_huey
管理命令将使用 autodiscover_modules("tasks")
.
tasks.py
为了让您的周期性任务被拾取,您需要在 tasks.py
中定义它们,或者让 tasks.py
导入定义它们的模块。