mirror of
https://github.com/thecyberlearn/quantum-ai-v2.git
synced 2026-08-18 08:52:59 +00:00
- Add expires_at field to ChatSession model with 2-hour default - Sessions automatically expire after 2 hours of inactivity - Active conversations extend session by 2 hours per message - Add session expiration checks in chat views - Create cleanup management command for expired sessions - Add session status indicators in chat UI - Fix null safety for existing sessions without expiration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
911 B
Python
30 lines
911 B
Python
from django.core.management.base import BaseCommand
|
|
from django.utils import timezone
|
|
from agents.models import ChatSession
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Mark expired chat sessions as expired'
|
|
|
|
def handle(self, *args, **options):
|
|
now = timezone.now()
|
|
|
|
# Find active sessions that have expired
|
|
expired_sessions = ChatSession.objects.filter(
|
|
status='active',
|
|
expires_at__lt=now
|
|
)
|
|
|
|
count = expired_sessions.count()
|
|
|
|
if count > 0:
|
|
# Mark them as expired
|
|
expired_sessions.update(
|
|
status='expired',
|
|
completed_at=now
|
|
)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(f'✅ Marked {count} expired sessions as expired')
|
|
)
|
|
else:
|
|
self.stdout.write('✅ No expired sessions found') |