diff options
-rw-r--r-- | server/handlers.py | 4 | ||||
-rw-r--r-- | server/prolog_session.py | 2 | ||||
-rw-r--r-- | server/python_session.py | 4 | ||||
-rw-r--r-- | server/robot_session.py | 4 | ||||
-rw-r--r-- | server/user_session.py | 9 |
5 files changed, 17 insertions, 6 deletions
diff --git a/server/handlers.py b/server/handlers.py index 42f53b4..619e2c2 100644 --- a/server/handlers.py +++ b/server/handlers.py @@ -127,7 +127,7 @@ class Activity(CodeqService): if problem_id is None: request.reply({'code': 1, 'message': 'Problem ID is missing'}) else: - request.session.update_solution(problem_id, trace, solution) + request.session.update_solution(problem_id, trace=trace, solution=solution) request.end() # no feedback, just acknowledge the reception @@ -169,7 +169,7 @@ class Query(CodeqService): else: result = {'code': 5, 'message': 'Unknown prolog step: {0}'.format(step)} if program or trace: - session.update_solution(problem_id, trace, program) + session.update_solution(problem_id, trace=trace, solution=program) request.reply(result) diff --git a/server/prolog_session.py b/server/prolog_session.py index dfb7c28..cd54e20 100644 --- a/server/prolog_session.py +++ b/server/prolog_session.py @@ -126,6 +126,8 @@ class PrologSession(server.LanguageSession): if pp != (p.group, p.identifier)] try: passed, hints = problem_module.test(program, solved_problems) + if passed: + session.update_solution(problem_id, done=True) except AttributeError as ex: hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}] diff --git a/server/python_session.py b/server/python_session.py index f7ec53f..4fcc3b5 100644 --- a/server/python_session.py +++ b/server/python_session.py @@ -13,6 +13,7 @@ import threading import time import server +import server.user_session from db.models import Problem __all__ = ['PythonSession'] @@ -110,6 +111,9 @@ class PythonSession(server.LanguageSession): try: passed, hints = problem_module.test(self.run, program) + if passed: + session = server.user_session.get_session_by_id(sid) + session.update_solution(problem_id, done=True) except AttributeError as ex: hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}] diff --git a/server/robot_session.py b/server/robot_session.py index 26da36e..137c16a 100644 --- a/server/robot_session.py +++ b/server/robot_session.py @@ -4,6 +4,7 @@ import threading from db.models import Problem import server +import server.user_session __all__ = ['RobotSession'] @@ -47,6 +48,9 @@ class RobotSession(server.LanguageSession): try: passed, hints = problem_module.test(program) + if passed: + session = server.user_session.get_session_by_id(sid) + session.update_solution(problem_id, done=True) except AttributeError as ex: hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}] diff --git a/server/user_session.py b/server/user_session.py index 976f144..8661016 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -273,8 +273,8 @@ class UserSession(object): pass db.return_connection(conn) - def update_solution(self, problem_id, trace, solution): - if (trace is None) and (solution is None): + def update_solution(self, problem_id, trace=None, solution=None, done=None): + if (trace is None) and (solution is None) and (done is None): return with self._access_lock: uid = self.uid @@ -283,7 +283,7 @@ class UserSession(object): cur = conn.cursor() try: # TODO: convert to upsert with postgresql 9.5 to eliminate the small window where it's possible for more than one concurrent insert to execute - cur.execute('select id, trace, content from solution where codeq_user_id = %s and problem_id = %s for update', (uid, problem_id)) + cur.execute('select id, trace, content, done from solution where codeq_user_id = %s and problem_id = %s for update', (uid, problem_id)) row = cur.fetchone() if row: if row[1]: @@ -293,7 +293,8 @@ class UserSession(object): else: new_trace = trace new_solution = row[2] if solution is None else solution - cur.execute('update solution set content = %s, trace = %s where id = %s', (new_solution, psycopg2.extras.Json(new_trace), row[0])) + new_done = row[3] if done is None else done + cur.execute('update solution set done = %s, content = %s, trace = %s where id = %s', (new_done, new_solution, psycopg2.extras.Json(new_trace), row[0])) else: # this is the first entry cur.execute('insert into solution (done, content, problem_id, codeq_user_id, trace) values (%s, %s, %s, %s, %s)', (False, solution, problem_id, uid, psycopg2.extras.Json(trace))) |