mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds a new task to periodically remove old error messages
This commit is contained in:
parent
bc3be635ae
commit
80d8645a0c
@ -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',
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user