Include forum status in LMS heartbeat service.

This commit is contained in:
Daniel Clemente Laboreo
2018-01-09 18:56:52 +02:00
parent 6a92b664d1
commit ce461b1d6e

View File

@@ -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)