Remove obsolete task

This commit is contained in:
Oliver Walters
2026-05-25 12:34:31 +00:00
parent cdd1b1d3a4
commit be132bf21d
2 changed files with 3 additions and 69 deletions
+3 -2
View File
@@ -89,11 +89,12 @@ class InvenTreeConfig(AppConfig):
def remove_obsolete_tasks(self): def remove_obsolete_tasks(self):
"""Delete any obsolete scheduled tasks in the database.""" """Delete any obsolete scheduled tasks in the database."""
obsolete = [ obsolete = [
'common.tasks.delete_old_notes_images',
'data_exporter.tasks.cleanup_old_export_outputs',
'InvenTree.tasks.delete_expired_sessions', 'InvenTree.tasks.delete_expired_sessions',
'stock.tasks.delete_old_stock_items',
'label.tasks.cleanup_old_label_outputs', 'label.tasks.cleanup_old_label_outputs',
'report.tasks.cleanup_old_report_outputs', 'report.tasks.cleanup_old_report_outputs',
'data_exporter.tasks.cleanup_old_export_outputs', 'stock.tasks.delete_old_stock_items',
] ]
try: try:
-67
View File
@@ -1,6 +1,5 @@
"""Tasks (processes that get offloaded) for common app.""" """Tasks (processes that get offloaded) for common app."""
import os
from datetime import timedelta from datetime import timedelta
from django.conf import settings from django.conf import settings
@@ -15,8 +14,6 @@ from opentelemetry import trace
import common.models import common.models
import InvenTree.helpers import InvenTree.helpers
from InvenTree.helpers_model import getModelsWithMixin
from InvenTree.models import InvenTreeNotesMixin
from InvenTree.tasks import ScheduledTask, scheduled_task from InvenTree.tasks import ScheduledTask, scheduled_task
tracer = trace.get_tracer(__name__) tracer = trace.get_tracer(__name__)
@@ -110,70 +107,6 @@ def update_news_feed():
logger.info('update_news_feed: Sync done') logger.info('update_news_feed: Sync done')
@tracer.start_as_current_span('delete_old_notes_images')
@scheduled_task(ScheduledTask.DAILY)
def delete_old_notes_images():
"""Remove old notes images from the database.
Anything older than ~3 months is removed, unless it is linked to a note
"""
try:
from common.models import NotesImage
except AppRegistryNotReady:
logger.info(
"Could not perform 'delete_old_notes_images' - App registry not ready"
)
return
# Remove any notes which point to non-existent image files
for note in NotesImage.objects.all():
if not os.path.exists(note.image.path):
logger.info('Deleting note %s - image file does not exist', note.image.path)
note.delete()
note_classes = getModelsWithMixin(InvenTreeNotesMixin)
before = InvenTree.helpers.current_date() - timedelta(days=90)
for note in NotesImage.objects.filter(date__lte=before):
# Find any images which are no longer referenced by a note
found = False
img = note.image.name
for model in note_classes:
if model.objects.filter(notes__icontains=img).exists():
found = True
break
if not found:
logger.info('Deleting note %s - image file not linked to a note', img)
note.delete()
# Finally, remove any images in the notes dir which are not linked to a note
notes_dir = os.path.join(settings.MEDIA_ROOT, 'notes')
try:
images = os.listdir(notes_dir)
except FileNotFoundError:
# Thrown if the directory does not exist
images = []
all_notes = NotesImage.objects.all()
for image in images:
found = False
for note in all_notes:
img_path = os.path.basename(note.image.path)
if img_path == image:
found = True
break
if not found:
logger.info('Deleting note %s - image file not linked to a note', image)
os.remove(os.path.join(notes_dir, image))
@tracer.start_as_current_span('rebuild_parameters') @tracer.start_as_current_span('rebuild_parameters')
def rebuild_parameters(template_id): def rebuild_parameters(template_id):
"""Rebuild all parameters for a given template. """Rebuild all parameters for a given template.