mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Adds a scheduled task to remove old notification entries from the database
This commit is contained in:
		@@ -76,6 +76,12 @@ class InvenTreeConfig(AppConfig):
 | 
				
			|||||||
            minutes=30,
 | 
					            minutes=30,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Delete old notification records
 | 
				
			||||||
 | 
					        InvenTree.tasks.schedule_task(
 | 
				
			||||||
 | 
					            'common.tasks.delete_old_notifications',
 | 
				
			||||||
 | 
					            schedule_type=Schedule.DAILY,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def update_exchange_rates(self):
 | 
					    def update_exchange_rates(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Update exchange rates each time the server is started, *if*:
 | 
					        Update exchange rates each time the server is started, *if*:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ from company.models import Company
 | 
				
			|||||||
from part.models import Part
 | 
					from part.models import Part
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
logger = logging.getLogger("inventree-thumbnails")
 | 
					logger = logging.getLogger('inventree')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Command(BaseCommand):
 | 
					class Command(BaseCommand):
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										29
									
								
								InvenTree/common/tasks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								InvenTree/common/tasks.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import logging
 | 
				
			||||||
 | 
					from datetime import timedelta, datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.core.exceptions import AppRegistryNotReady
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					logger = logging.getLogger('inventree')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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:
 | 
				
			||||||
 | 
					        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()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user