Skip to content

Commit

Permalink
Merge pull request #3210 from kobotoolbox/3158-mongo-query-timeout-2
Browse files Browse the repository at this point in the history
Mongo query timeout
  • Loading branch information
noliveleger authored May 19, 2021
2 parents 8d3b938 + e43f206 commit d255df4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions kobo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 5 additions & 1 deletion kpi/utils/mongo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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=settings.MONGO_DB_MAX_TIME_MS
)
return cursor, cursor.count()

@classmethod
Expand Down

0 comments on commit d255df4

Please sign in to comment.