Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions web/pgadmin/misc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pgadmin.utils.heartbeat import log_server_heartbeat, \
get_server_heartbeat, stop_server_heartbeat
import config
import threading
import time
import json
import os
Expand Down Expand Up @@ -183,6 +184,19 @@ def register(self, app, options):
from .workspaces import blueprint as module
self.submodules.append(module)

def autovacuum_sessions():
try:
with app.app_context():
cleanup_session_files()
finally:
# repeat every five minutes until exit
# https://github.com/python/cpython/issues/98230
t = threading.Timer(5 * 60, autovacuum_sessions)
t.daemon = True
t.start()

app.register_before_app_start(autovacuum_sessions)

super().register(app, options)


Expand Down Expand Up @@ -213,8 +227,6 @@ def ping():
@pgCSRFProtect.exempt
def cleanup():
driver.ping()
# Cleanup session files.
cleanup_session_files()
return ""


Expand Down
11 changes: 11 additions & 0 deletions web/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from pgadmin import create_app
from pgadmin.utils import clear_database_servers, dump_database_servers, \
load_database_servers, _handle_error
from pgadmin.utils.session import cleanup_session_files
from pgadmin.setup import db_upgrade, create_app_data_directory
from typing import Optional, List
from typing_extensions import Annotated
Expand Down Expand Up @@ -636,6 +637,16 @@ def run_migration_for_others():
run_migration_for_sqlite()


class ManageSessions:

@app.command()
def cleanup_session_files():
"""Delete expired session files."""
app = create_app(config.APP_NAME + '-cli')
with app.app_context():
cleanup_session_files()


def main():
app()

Expand Down