Debian Codegraph @

django/contrib/sessions/management/commands/clearsessions.py

raw
1 from importlib import import_module
2
3 from django.conf import settings
4 from django.core.management.base import BaseCommand, CommandError
5
6
7 class Command(BaseCommand):
8 help = (
9 "Can be run as a cronjob or directly to clean out expired sessions "
10 "when the backend supports it."
11 )
12
13 def handle(self, **options):
14 engine = import_module(settings.SESSION_ENGINE)
15 try:
16 engine.SessionStore.clear_expired()
17 except NotImplementedError:
18 raise CommandError(
19 "Session engine '%s' doesn't support clearing expired "
20 "sessions." % settings.SESSION_ENGINE
21 )