2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00
Files
InvenTree/InvenTree/common/tasks.py
Matthias Mair 269b269de3 Fix task register (#3805)
* fix schedule registration

* add collection step for tasks

* make tasks register configurable

* extend docs

* Also run InvenTree setup in testing

* fix import loading method

* fix wrong task registration

* do not test

* do only distinct testing

* ignore import error for coverage
2022-10-18 16:54:10 +11:00

29 lines
847 B
Python

"""Tasks (processes that get offloaded) for common app."""
import logging
from datetime import datetime, timedelta
from django.core.exceptions import AppRegistryNotReady
from InvenTree.tasks import ScheduledTask, scheduled_task
logger = logging.getLogger('inventree')
@scheduled_task(ScheduledTask.DAILY)
def delete_old_notifications():
"""Remove old notifications from the database.
Anything older than ~3 months is removed
"""
try:
from common.models import NotificationEntry
except AppRegistryNotReady: # pragma: no cover
logger.info("Could not perform 'delete_old_notifications' - App registry not ready")
return
before = datetime.now() - timedelta(days=90)
# Delete notification records before the specified date
NotificationEntry.objects.filter(updated__lte=before).delete()