mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Run periodic (daily) task to clear out expired sessions
This commit is contained in:
parent
c3048a1bf1
commit
f0415640d5
@ -32,27 +32,37 @@ class InvenTreeConfig(AppConfig):
|
|||||||
|
|
||||||
logger.info("Starting background tasks...")
|
logger.info("Starting background tasks...")
|
||||||
|
|
||||||
|
# Remove successful task results from the database
|
||||||
InvenTree.tasks.schedule_task(
|
InvenTree.tasks.schedule_task(
|
||||||
'InvenTree.tasks.delete_successful_tasks',
|
'InvenTree.tasks.delete_successful_tasks',
|
||||||
schedule_type=Schedule.DAILY,
|
schedule_type=Schedule.DAILY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check for InvenTree updates
|
||||||
InvenTree.tasks.schedule_task(
|
InvenTree.tasks.schedule_task(
|
||||||
'InvenTree.tasks.check_for_updates',
|
'InvenTree.tasks.check_for_updates',
|
||||||
schedule_type=Schedule.DAILY
|
schedule_type=Schedule.DAILY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Heartbeat to let the server know the background worker is running
|
||||||
InvenTree.tasks.schedule_task(
|
InvenTree.tasks.schedule_task(
|
||||||
'InvenTree.tasks.heartbeat',
|
'InvenTree.tasks.heartbeat',
|
||||||
schedule_type=Schedule.MINUTES,
|
schedule_type=Schedule.MINUTES,
|
||||||
minutes=15
|
minutes=15
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Keep exchange rates up to date
|
||||||
InvenTree.tasks.schedule_task(
|
InvenTree.tasks.schedule_task(
|
||||||
'InvenTree.tasks.update_exchange_rates',
|
'InvenTree.tasks.update_exchange_rates',
|
||||||
schedule_type=Schedule.DAILY,
|
schedule_type=Schedule.DAILY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Remove expired sessions
|
||||||
|
InvenTree.tasks.schedule_task(
|
||||||
|
'InvenTree.tasks.delete_expired_sessions',
|
||||||
|
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*:
|
||||||
|
@ -204,6 +204,25 @@ 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 True or 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():
|
def update_exchange_rates():
|
||||||
"""
|
"""
|
||||||
Update currency exchange rates
|
Update currency exchange rates
|
||||||
|
Loading…
Reference in New Issue
Block a user