Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue2250

This commit is contained in:
Matthias 2021-12-08 18:26:49 +01:00
commit cfa576d03d
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 21 additions and 25 deletions

View File

@ -18,11 +18,32 @@ class InvenTreeConfig(AppConfig):
def ready(self):
if canAppAccessDatabase():
self.remove_obsolete_tasks()
self.start_background_tasks()
if not isInTestMode():
self.update_exchange_rates()
def remove_obsolete_tasks(self):
"""
Delete any obsolete scheduled tasks in the database
"""
obsolete = [
'InvenTree.tasks.delete_expired_sessions',
'stock.tasks.delete_old_stock_items',
]
try:
from django_q.models import Schedule
except (AppRegistryNotReady):
return
# Remove any existing obsolete tasks
Schedule.objects.filter(func__in=obsolete).delete()
def start_background_tasks(self):
try:
@ -57,12 +78,6 @@ class InvenTreeConfig(AppConfig):
schedule_type=Schedule.DAILY,
)
# Remove expired sessions
InvenTree.tasks.schedule_task(
'InvenTree.tasks.delete_expired_sessions',
schedule_type=Schedule.DAILY,
)
# Delete old error messages
InvenTree.tasks.schedule_task(
'InvenTree.tasks.delete_old_error_logs',

View File

@ -231,25 +231,6 @@ def check_for_updates():
)
def delete_expired_sessions():
"""
Remove any expired user sessions from the database
"""
try:
from django.contrib.sessions.models import Session
# Delete any sessions that expired more than a day ago
expired = Session.objects.filter(expire_date__lt=timezone.now() - timedelta(days=1))
if expired.count() > 0:
logger.info(f"Deleting {expired.count()} expired sessions.")
expired.delete()
except AppRegistryNotReady:
logger.info("Could not perform 'delete_expired_sessions' - App registry not ready")
def update_exchange_rates():
"""
Update currency exchange rates