I have configured background tasks in my Django App according to docs. The structure of my app is as follows:
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
runs the task when the method is invoked under some view. The issue is that if its invoked under a view it will be invoked way too many times and the repeat will unnecessarily overload.
What mistake am I making under the auto discovery? Is it necessary to manually invoke the method even after running python manage.py process_tasks
? Thank you.
Then you need to run a daily job to hard delete tasks deleted more than 14 days ago. You have 3 options to do that:
Write your own django command and add it manually to a crontab on the server.
Use django-cron
Use django-crontab