From 59bf0146ac5d7ad4b0fdef9dc65885d9ff8c808f Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Tue, 5 Mar 2024 17:24:38 +1100 Subject: [PATCH 1/3] Fix output for logging analytics events. --- session-manager/handlers/analytics.py | 15 ++++++--------- .../project/apps/workshops/manager/analytics.py | 11 ++++++----- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/session-manager/handlers/analytics.py b/session-manager/handlers/analytics.py index a7e41d2a..4d9f87bd 100644 --- a/session-manager/handlers/analytics.py +++ b/session-manager/handlers/analytics.py @@ -21,13 +21,6 @@ def send_event_to_webhook(url, message): def report_analytics_event(event, data={}): - message = None - - logging.info("Reporting analytics event %s with data %s.", event, data) - - if not ANALYTICS_WEBHOOK_URL: - return - message = { "event": { "name": event, @@ -36,5 +29,9 @@ def report_analytics_event(event, data={}): }, } - if message: - send_event_to_webhook(ANALYTICS_WEBHOOK_URL, message) + logging.info("Reporting analytics event %s as message %s.", event, message) + + if not ANALYTICS_WEBHOOK_URL: + return + + send_event_to_webhook(ANALYTICS_WEBHOOK_URL, message) diff --git a/training-portal/src/project/apps/workshops/manager/analytics.py b/training-portal/src/project/apps/workshops/manager/analytics.py index 886e5aca..0a5f621b 100644 --- a/training-portal/src/project/apps/workshops/manager/analytics.py +++ b/training-portal/src/project/apps/workshops/manager/analytics.py @@ -19,11 +19,6 @@ def send_event_to_webhook(url, message): def report_analytics_event(entity, event, data={}): message = None - logging.info("Reporting analytics event %s with data %s.", event, data) - - if not settings.ANALYTICS_WEBHOOK_URL: - return - if event.startswith("User/"): user = entity @@ -85,5 +80,11 @@ def report_analytics_event(entity, event, data={}): }, } + if message: + logging.info("Reporting analytics event %s as message %s.", event, message) + + if not settings.ANALYTICS_WEBHOOK_URL: + return + if message: send_event_to_webhook(settings.ANALYTICS_WEBHOOK_URL, message).schedule() From 40a2cf3e34b0914bc7abd2c073e55a144fae344e Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 7 Mar 2024 19:47:08 +1100 Subject: [PATCH 2/3] Ensure database transaction is atomic. --- training-portal/src/project/apps/workshops/views/session.py | 1 + 1 file changed, 1 insertion(+) diff --git a/training-portal/src/project/apps/workshops/views/session.py b/training-portal/src/project/apps/workshops/views/session.py index 8fec2993..922955bc 100644 --- a/training-portal/src/project/apps/workshops/views/session.py +++ b/training-portal/src/project/apps/workshops/views/session.py @@ -199,6 +199,7 @@ def session_terminate(request, name): @login_required(login_url="/") @require_http_methods(["GET"]) @resources_lock +@transaction.atomic def session_delete(request, name): """Triggers deletion of a workshop session.""" From 96e8d158ea06263c8b927a8af8876ebb87bbd61f Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 7 Mar 2024 20:04:43 +1100 Subject: [PATCH 3/3] Increase default SQLite database timeout to 15s. --- training-portal/src/project/settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/training-portal/src/project/settings.py b/training-portal/src/project/settings.py index 44d425b1..f6776985 100644 --- a/training-portal/src/project/settings.py +++ b/training-portal/src/project/settings.py @@ -79,6 +79,9 @@ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(DATA_DIR, "db.sqlite3"), + "OPTIONS": { + "timeout": 15, + } } }