Django 后台任务自动发现不起作用
Django Background Tasks autodiscovery not working
我已经根据文档在我的 Django 应用程序中配置了后台任务。我的应用程序结构如下:
todo_app
|
task
| |
| models, tests, urls, admin, apps
|
|
frontend
| |
| tasks.py
| |
| models, tests, urls, admin, apps
|
manage.py
|
|todo_app
|
settings, urls, wsgi etc
settings.py:
INSTALLED_APPS = [
...
'background_task',
...
]
BACKGROUND_TASK_RUN_ASYNC = True
tasks.py:
from background_task import background
@background(schedule=1)
def task_runner(repeat=3):
print("hello world")
python manage.py process_tasks
在某个视图下调用方法时运行任务。问题是,如果它在一个视图下被调用,它将被调用太多次并且重复将不必要地超载。
我在自动发现下犯了什么错误? 运行python manage.py process_tasks
之后还需要手动调用方法吗?谢谢。
那么您需要运行一个daily job硬删除超过14天前删除的任务。您有 3 个选择:
自己写django command and add it manually to a crontab on the server.
我已经根据文档在我的 Django 应用程序中配置了后台任务。我的应用程序结构如下:
todo_app
|
task
| |
| models, tests, urls, admin, apps
|
|
frontend
| |
| tasks.py
| |
| models, tests, urls, admin, apps
|
manage.py
|
|todo_app
|
settings, urls, wsgi etc
settings.py:
INSTALLED_APPS = [
...
'background_task',
...
]
BACKGROUND_TASK_RUN_ASYNC = True
tasks.py:
from background_task import background
@background(schedule=1)
def task_runner(repeat=3):
print("hello world")
python manage.py process_tasks
在某个视图下调用方法时运行任务。问题是,如果它在一个视图下被调用,它将被调用太多次并且重复将不必要地超载。
我在自动发现下犯了什么错误? 运行python manage.py process_tasks
之后还需要手动调用方法吗?谢谢。
那么您需要运行一个daily job硬删除超过14天前删除的任务。您有 3 个选择:
自己写django command and add it manually to a crontab on the server.