Skip to content

Commit

Permalink
fix(sessions): Clean old expired sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Feb 8, 2025
1 parent 88e0409 commit 0da3305
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dojo/db_migrations/0222_clean_old_sessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import migrations

class Migration(migrations.Migration):

dependencies = [
('sessions', '0001_initial'),
]

operations = [
migrations.RunSQL("DELETE FROM django_session WHERE expire_date < NOW();"),
migrations.RunSQL("VACUUM django_session;"),
]
4 changes: 4 additions & 0 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@ def saml2_attrib_map_format(din):
"task": "dojo.tasks.evaluate_pro_proposition",
"schedule": timedelta(hours=8),
},
"clear_sessions": {
"task": "dojo.tasks.clear_sessions",
"schedule": crontab(hour=0, minute=0, day_of_week=0),
},
# 'jira_status_reconciliation': {
# 'task': 'dojo.tasks.jira_status_reconciliation_task',
# 'schedule': timedelta(hours=12),
Expand Down
6 changes: 6 additions & 0 deletions dojo/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from celery.utils.log import get_task_logger
from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.core.management import call_command
from django.db.models import Count, Prefetch
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -216,3 +217,8 @@ def evaluate_pro_proposition(*args, **kwargs):
# Update the announcement
announcement.message = f'Only professionals have {object_count:,} Findings and Endpoints in their systems... <a href="https://www.defectdojo.com/pricing" target="_blank">Get DefectDojo Pro</a> today!'
announcement.save()


@app.task
def clear_sessions(*args, **kwargs):
call_command("clearsessions")

0 comments on commit 0da3305

Please sign in to comment.