Merge pull request #2113 from SchrodingersGat/delete-error-logs

Adds a new task  to periodically remove old error messages
This commit is contained in:
Oliver 2021-10-06 21:36:15 +11:00 committed by GitHub
commit 54d770927a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -63,6 +63,12 @@ class InvenTreeConfig(AppConfig):
schedule_type=Schedule.DAILY,
)
# Delete old error messages
InvenTree.tasks.schedule_task(
'InvenTree.tasks.delete_old_error_logs',
schedule_type=Schedule.DAILY,
)
# Delete "old" stock items
InvenTree.tasks.schedule_task(
'stock.tasks.delete_old_stock_items',

View File

@ -156,9 +156,36 @@ def delete_successful_tasks():
started__lte=threshold
)
if results.count() > 0:
logger.info(f"Deleting {results.count()} successful task records")
results.delete()
def delete_old_error_logs():
"""
Delete old error logs from the server
"""
try:
from error_report.models import Error
# Delete any error logs more than 30 days old
threshold = timezone.now() - timedelta(days=30)
errors = Error.objects.filter(
when__lte=threshold,
)
if errors.count() > 0:
logger.info(f"Deleting {errors.count()} old error logs")
errors.delete()
except AppRegistryNotReady:
# Apps not yet loaded
logger.info("Could not perform 'delete_old_error_logs' - App registry not ready")
return
def check_for_updates():
"""
Check if there is an update for InvenTree
@ -215,7 +242,7 @@ def delete_expired_sessions():
# Delete any sessions that expired more than a day ago
expired = Session.objects.filter(expire_date__lt=timezone.now() - timedelta(days=1))
if True or expired.count() > 0:
if expired.count() > 0:
logger.info(f"Deleting {expired.count()} expired sessions.")
expired.delete()
@ -247,15 +274,15 @@ def update_exchange_rates():
pass
except:
# Some other error
print("Database not ready")
logger.warning("update_exchange_rates: Database not ready")
return
backend = InvenTreeExchange()
print(f"Updating exchange rates from {backend.url}")
logger.info(f"Updating exchange rates from {backend.url}")
base = currency_code_default()
print(f"Using base currency '{base}'")
logger.info(f"Using base currency '{base}'")
backend.update_rates(base_currency=base)