mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue2250
This commit is contained in:
commit
cfa576d03d
@ -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',
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user