summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--[-rwxr-xr-x]yaksh/code_server.py0
-rw-r--r--[-rwxr-xr-x]yaksh/docs/sample.sh0
-rw-r--r--yaksh/models.py12
-rw-r--r--yaksh/settings.py11
-rw-r--r--yaksh/views.py7
5 files changed, 18 insertions, 12 deletions
diff --git a/yaksh/code_server.py b/yaksh/code_server.py
index 75dd9b2..75dd9b2 100755..100644
--- a/yaksh/code_server.py
+++ b/yaksh/code_server.py
diff --git a/yaksh/docs/sample.sh b/yaksh/docs/sample.sh
index e935cb3..e935cb3 100755..100644
--- a/yaksh/docs/sample.sh
+++ b/yaksh/docs/sample.sh
diff --git a/yaksh/models.py b/yaksh/models.py
index 1d24bda..2f616cf 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -29,10 +29,10 @@ import tempfile
from textwrap import dedent
from ast import literal_eval
from .file_utils import extract_files, delete_files
-from yaksh.code_server import(submit,
- get_result as get_result_from_code_server
- )
-from yaksh.settings import SERVER_POOL_PORT
+from yaksh.code_server import (
+ submit, get_result as get_result_from_code_server
+)
+from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME
from django.conf import settings
from django.forms.models import model_to_dict
@@ -1705,7 +1705,7 @@ class AnswerPaper(models.Model):
elif question.type == 'code' or question.type == "upload":
user_dir = self.user.profile.get_user_dir()
- url = 'http://localhost:%s' % server_port
+ url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port)
submit(url, uid, json_data, user_dir)
result = {'uid': uid, 'status': 'running'}
return result
@@ -1740,7 +1740,7 @@ class AnswerPaper(models.Model):
server_port=server_port
)
if question.type == "code":
- url = 'http://localhost:%s' % server_port
+ url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port)
check_result = get_result_from_code_server(url, result['uid'],
block=True
)
diff --git a/yaksh/settings.py b/yaksh/settings.py
index d500d93..d895d19 100644
--- a/yaksh/settings.py
+++ b/yaksh/settings.py
@@ -2,16 +2,21 @@
settings for yaksh app.
"""
+from decouple import config
+
# The number of code server processes to run..
-N_CODE_SERVERS = 5
+N_CODE_SERVERS = config('N_CODE_SERVERS', default=5, cast=int)
# The server pool port. This is the server which returns available server
# ports so as to minimize load. This is some random number where no other
# service is running. It should be > 1024 and less < 65535 though.
-SERVER_POOL_PORT = 53579
+SERVER_POOL_PORT = config('SERVER_POOL_PORT', default=55555, cast=int)
+
+SERVER_HOST_NAME = config('SERVER_HOST_NAME', default='http://localhost')
+#'localhost'
# Timeout for the code to run in seconds. This is an integer!
-SERVER_TIMEOUT = 4
+SERVER_TIMEOUT = config('SERVER_TIMEOUT', default=4, cast=int)
# The root of the URL, for example you might be in the situation where you
# are not hosted as host.org/exam/ but as host.org/foo/exam/ for whatever
diff --git a/yaksh/views.py b/yaksh/views.py
index a4d9e78..8fe4523 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -35,7 +35,7 @@ except ImportError:
from io import BytesIO as string_io
import re
# Local imports.
-from yaksh.code_server import get_result as get_result_from_code_server, SERVER_POOL_PORT
+from yaksh.code_server import get_result as get_result_from_code_server
from yaksh.models import (
Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase,
HookTestCase, IntegerTestCase, McqTestCase, Profile,
@@ -51,6 +51,7 @@ from yaksh.forms import (
UploadFileForm, get_object_form, FileForm, QuestionPaperForm, LessonForm,
LessonFileForm, LearningModuleForm, ExerciseForm
)
+from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME
from .settings import URL_ROOT
from .file_utils import extract_files, is_csv
from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail
@@ -782,7 +783,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None,
)
if current_question.type in ['code', 'upload']:
if paper.time_left() <= 0 and not paper.question_paper.quiz.is_exercise:
- url = 'http://localhost:%s' % SERVER_POOL_PORT
+ url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT)
result_details = get_result_from_code_server(url, uid, block=True)
result = json.loads(result_details.get('result'))
next_question, error_message, paper = _update_paper(request, uid,
@@ -807,7 +808,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None,
@csrf_exempt
def get_result(request, uid, course_id, module_id):
result = {}
- url = 'http://localhost:%s' % SERVER_POOL_PORT
+ url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT)
result_state = get_result_from_code_server(url, uid)
result['status'] = result_state.get('status')
if result['status'] == 'done':