INCR-349 python3 compatibility

This commit is contained in:
Ayub khan
2019-07-10 13:32:32 +05:00
parent 3e9f503de5
commit 2250411222
6 changed files with 30 additions and 12 deletions

View File

@@ -3,23 +3,27 @@ A set of built-in default checks for the platform heartbeat endpoint
Other checks should be included in their respective modules/djangoapps
"""
from __future__ import absolute_import
from datetime import datetime, timedelta
from time import sleep, time
import six
from django.conf import settings
from django.core.cache import cache
from django.db import connection
from django.db.utils import DatabaseError
from xmodule.modulestore.django import modulestore
from xmodule.exceptions import HeartbeatFailure
from xmodule.modulestore.django import modulestore
from .tasks import sample_task
# DEFAULT SYSTEM CHECKS
# Modulestore
def check_modulestore():
""" Check the modulestore connection
@@ -37,7 +41,7 @@ def check_modulestore():
modulestore().heartbeat()
return 'modulestore', True, u'OK'
except HeartbeatFailure as fail:
return 'modulestore', False, unicode(fail)
return 'modulestore', False, six.text_type(fail)
def check_database():
@@ -54,7 +58,7 @@ def check_database():
cursor.fetchone()
return 'sql', True, u'OK'
except DatabaseError as fail:
return 'sql', False, unicode(fail)
return 'sql', False, six.text_type(fail)
# Caching
@@ -74,7 +78,7 @@ def check_cache_set():
cache.set(CACHE_KEY, CACHE_VALUE, 30)
return 'cache_set', True, u'OK'
except Exception as fail:
return 'cache_set', False, unicode(fail)
return 'cache_set', False, six.text_type(fail)
def check_cache_get():
@@ -92,7 +96,7 @@ def check_cache_get():
else:
return 'cache_get', False, u'value check failed'
except Exception as fail:
return 'cache_get', False, unicode(fail)
return 'cache_get', False, six.text_type(fail)
# Celery
@@ -113,8 +117,8 @@ def check_celery():
while expires > datetime.now():
if task.ready() and task.result:
finished = str(time() - now)
return 'celery', True, unicode({'time': finished})
return 'celery', True, six.text_type({'time': finished})
sleep(0.25)
return 'celery', False, "expired"
except Exception as fail:
return 'celery', False, unicode(fail)
return 'celery', False, six.text_type(fail)

View File

@@ -1,3 +1,8 @@
"""
Code for system checks.
"""
from __future__ import absolute_import
from importlib import import_module
from django.conf import settings

View File

@@ -1,6 +1,8 @@
"""
A trivial task for health checks
"""
from __future__ import absolute_import
from celery.task import task

View File

@@ -1,16 +1,17 @@
"""
Test the heartbeat
"""
from __future__ import print_function
from __future__ import absolute_import, print_function
import json
from django.urls import reverse
from django.db.utils import DatabaseError
from django.test.client import Client
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from django.urls import reverse
from mock import patch
from xmodule.exceptions import HeartbeatFailure
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class HeartbeatTestCase(ModuleStoreTestCase):

View File

@@ -1,6 +1,8 @@
"""
Urls for verifying health (heartbeat) of the app.
"""
from __future__ import absolute_import
from django.conf.urls import url
from openedx.core.djangoapps.heartbeat.views import heartbeat

View File

@@ -1,6 +1,10 @@
"""
Views for verifying the health (heartbeat) of the app.
"""
from __future__ import absolute_import
import six
from util.json_request import JsonResponse
from .runchecks import runchecks
@@ -22,6 +26,6 @@ def heartbeat(request):
status_code = 503 # 503 on any failure
except Exception as e:
status_code = 503
check_results = {'error': unicode(e)}
check_results = {'error': six.text_type(e)}
return JsonResponse(check_results, status=status_code)