Skip to content
Snippets Groups Projects
Unverified Commit 1eb8b3a9 authored by John Eskew's avatar John Eskew Committed by GitHub
Browse files

Merge pull request #17147 from open-craft/clemente/add-forum-to-heartbeat

Allow to include forum status in LMS heartbeat service.
parents 381af53a ce461b1d
No related merge requests found
......@@ -8,6 +8,7 @@ import requests
from django.utils.translation import get_language
import dogstats_wrapper as dog_stats_api
from .settings import SERVICE_HOST as COMMENTS_SERVICE
log = logging.getLogger(__name__)
......@@ -171,3 +172,30 @@ class CommentClientPaginatedResult(object):
self.num_pages = num_pages
self.thread_count = thread_count
self.corrected_text = corrected_text
def check_forum_heartbeat():
"""
Check the forum connection via its built-in heartbeat service and create an answer which can be used in the LMS
heartbeat django application.
This function can be connected to the LMS heartbeat checker through the HEARTBEAT_CHECKS variable.
"""
# To avoid dependency conflict
from django_comment_common.models import ForumsConfig
config = ForumsConfig.current()
if not config.enabled:
# If this check is enabled but forums disabled, don't connect, just report no error
return 'forum', True, 'OK'
try:
res = requests.get(
'%s/heartbeat' % COMMENTS_SERVICE,
timeout=config.connection_timeout
).json()
if res['OK']:
return 'forum', True, 'OK'
else:
return 'forum', False, res.get('check', 'Forum heartbeat failed')
except Exception as fail:
return 'forum', False, unicode(fail)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment