From e013ed0046c76c15a5fe8a288b105463b53457c2 Mon Sep 17 00:00:00 2001 From: JacquelineMorrissette Date: Wed, 12 May 2021 11:10:15 -0400 Subject: [PATCH 1/4] applied max_timeout_ms to mongo query --- kpi/utils/mongo_helper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kpi/utils/mongo_helper.py b/kpi/utils/mongo_helper.py index 2761e78c08..98331d8784 100644 --- a/kpi/utils/mongo_helper.py +++ b/kpi/utils/mongo_helper.py @@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ +from kobo.settings.base import CELERY_TASK_TIME_LIMIT from kpi.constants import NESTED_MONGO_RESERVED_ATTRIBUTES from kpi.utils.strings import base64_encodestring @@ -292,7 +293,11 @@ def _get_cursor_and_count(cls, mongo_userform_id, hide_deleted=True, # Retrieve all fields except `cls.USERFORM_ID` fields_to_select = {cls.USERFORM_ID: 0} - cursor = settings.MONGO_DB.instances.find(query, fields_to_select) + cursor = settings.MONGO_DB.instances.find( + query, + fields_to_select, + max_time_ms=CELERY_TASK_TIME_LIMIT*1000 + ) return cursor, cursor.count() @classmethod From 4956eed82090b0d5953032ac8fdf8c6db911d0fb Mon Sep 17 00:00:00 2001 From: JacquelineMorrissette Date: Thu, 13 May 2021 21:38:23 -0400 Subject: [PATCH 2/4] Added MONGO_DB_MAX_TIME_MS as env. variable --- kobo/settings/base.py | 2 ++ kpi/utils/mongo_helper.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kobo/settings/base.py b/kobo/settings/base.py index adc4803b21..1e5342544b 100644 --- a/kobo/settings/base.py +++ b/kobo/settings/base.py @@ -700,6 +700,8 @@ def __init__(self, *args, **kwargs): MONGO_CONNECTION_URL, j=True, tz_aware=True, connect=False) MONGO_DB = MONGO_CONNECTION[MONGO_DATABASE['NAME']] +MONGO_DB_MAX_TIME_MS = CELERY_TASK_TIME_LIMIT * 60 * 1000 + SESSION_ENGINE = "redis_sessions.session" SESSION_REDIS = RedisHelper.config(default="redis://redis_cache:6380/2") diff --git a/kpi/utils/mongo_helper.py b/kpi/utils/mongo_helper.py index 98331d8784..eacbfe9fa8 100644 --- a/kpi/utils/mongo_helper.py +++ b/kpi/utils/mongo_helper.py @@ -296,7 +296,7 @@ def _get_cursor_and_count(cls, mongo_userform_id, hide_deleted=True, cursor = settings.MONGO_DB.instances.find( query, fields_to_select, - max_time_ms=CELERY_TASK_TIME_LIMIT*1000 + max_time_ms=MONGO_DB_MAX_TIME_MS ) return cursor, cursor.count() From 77de5a93873a80d53b9bb7f1543e322e65dbf6d4 Mon Sep 17 00:00:00 2001 From: JacquelineMorrissette Date: Thu, 13 May 2021 21:41:08 -0400 Subject: [PATCH 3/4] removed Celery from imports --- kpi/utils/mongo_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kpi/utils/mongo_helper.py b/kpi/utils/mongo_helper.py index eacbfe9fa8..f966b0a81b 100644 --- a/kpi/utils/mongo_helper.py +++ b/kpi/utils/mongo_helper.py @@ -6,7 +6,6 @@ from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ -from kobo.settings.base import CELERY_TASK_TIME_LIMIT from kpi.constants import NESTED_MONGO_RESERVED_ATTRIBUTES from kpi.utils.strings import base64_encodestring From e43f206ca07287f56a7c18302b731dc7fa81feca Mon Sep 17 00:00:00 2001 From: JacquelineMorrissette <74968475+JacquelineMorrissette@users.noreply.github.com> Date: Mon, 17 May 2021 13:08:49 -0400 Subject: [PATCH 4/4] edited variable path --- kpi/utils/mongo_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpi/utils/mongo_helper.py b/kpi/utils/mongo_helper.py index f966b0a81b..71c31c84ba 100644 --- a/kpi/utils/mongo_helper.py +++ b/kpi/utils/mongo_helper.py @@ -295,7 +295,7 @@ def _get_cursor_and_count(cls, mongo_userform_id, hide_deleted=True, cursor = settings.MONGO_DB.instances.find( query, fields_to_select, - max_time_ms=MONGO_DB_MAX_TIME_MS + max_time_ms=settings.MONGO_DB_MAX_TIME_MS ) return cursor, cursor.count()