Skip to content

Commit

Permalink
feat: support logging of ping errors (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 authored Apr 26, 2021
1 parent 2594a63 commit 1444ca4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Change Log
Unreleased
~~~~~~~~~~

[3.8.8] - 2021-04-23
~~~~~~~~~~~~~~~~~~~~
* Add detailed logging of ping failures
* Expose ping timeout value to external javascript worker
* Add documentation for javascript worker development

[3.8.7] - 2021-04-16
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"""

# Be sure to update the version number in edx_proctoring/package.json
__version__ = '3.8.7'
__version__ = '3.8.8'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
4 changes: 2 additions & 2 deletions edx_proctoring/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const handlerWrapper = (Handler) => {
}
case 'ping': {
if (handler.onPing) {
handler.onPing()
handler.onPing(message.data.timeout)
.then(() => self.postMessage({ type: 'echo' }))
.catch(() => self.postMessage({ type: 'pingFailed' }));
.catch(error => self.postMessage({ type: 'pingFailed', error }));
}
break;
}
Expand Down
19 changes: 12 additions & 7 deletions edx_proctoring/static/proctoring/js/exam_action_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ edx = edx || {};
}

function workerPromiseForEventNames(eventNames) {
return function() {
return function(timeout) {
var proctoringBackendWorker = createWorker(edx.courseware.proctored_exam.configuredWorkerURL);
return new Promise(function(resolve, reject) {
var responseHandler = function(e) {
Expand All @@ -64,18 +64,21 @@ edx = edx || {};
proctoringBackendWorker.terminate();
resolve();
} else {
reject();
reject(e.data.error);
}
};
proctoringBackendWorker.addEventListener('message', responseHandler);
proctoringBackendWorker.postMessage({type: eventNames.promptEventName});
proctoringBackendWorker.postMessage({type: eventNames.promptEventName, timeout: timeout});
});
};
}

function timeoutPromise(timeoutMilliseconds) {
function workerTimeoutPromise(timeoutMilliseconds) {
var message = 'worker failed to respond after ' + timeoutMilliseconds + 'ms';
return new Promise(function(resolve, reject) {
setTimeout(reject, timeoutMilliseconds);
setTimeout(function() {
reject(Error(message));
}, timeoutMilliseconds);
});
}

Expand Down Expand Up @@ -233,9 +236,11 @@ edx = edx || {};
}
};
edx.courseware.proctored_exam.pingApplication = function(timeoutInSeconds) {
var TIMEOUT_BUFFER_SECONDS = 10;
var workerPingTimeout = timeoutInSeconds - TIMEOUT_BUFFER_SECONDS; // 10s buffer for worker to respond
return Promise.race([
workerPromiseForEventNames(actionToMessageTypesMap.ping)(),
timeoutPromise(timeoutInSeconds * 1000)
workerPromiseForEventNames(actionToMessageTypesMap.ping)(workerPingTimeout * 1000),
workerTimeoutPromise(timeoutInSeconds * 1000)
]);
};
edx.courseware.proctored_exam.accessibleError = accessibleError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ edx = edx || {};
this.model.get('attempt_status') !== 'ready_to_submit'
) {
edx.courseware.proctored_exam.pingApplication(pingInterval)
.catch(self.endExamForFailureState.bind(self));
.catch(function(error) {
self.endExamForFailureState(error);
});
}
if (self.timerTick % self.poll_interval === 0) {
url = self.model.url + '/' + self.model.get('attempt_id');
Expand Down Expand Up @@ -216,11 +218,12 @@ edx = edx || {};
edx.courseware.proctored_exam.endExam(self.model.get('exam_started_poll_url')).then(self.reloadPage);
}
},
endExamForFailureState: function() {
endExamForFailureState: function(error) {
var self = this;
return $.ajax({
data: {
action: 'error'
action: 'error',
detail: String(error)
},
url: this.model.url + '/' + this.model.get('attempt_id'),
type: 'PUT'
Expand Down
8 changes: 5 additions & 3 deletions edx_proctoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ def put(self, request, attempt_id):

course_id = attempt['proctored_exam']['course_id']
action = request.data.get('action')
detail = request.data.get('detail')

err_msg = (
'user_id={user_id} attempted to update attempt_id={attempt_id} in '
Expand Down Expand Up @@ -804,14 +805,15 @@ def put(self, request, attempt_id):
else:
exam_attempt_id = False
LOG.warning(
'Browser JS reported problem with proctoring desktop application. Did block user: '
'{should_block_user}. user_id={user_id}, course_id={course_id}, exam_id={exam_id}, '
'attempt_id={attempt_id}'.format(
'Browser JS reported problem with proctoring desktop application. Error detail: '
'{error_detail}. Did block user: {should_block_user}. user_id={user_id}, '
'course_id={course_id}, exam_id={exam_id}, attempt_id={attempt_id}'.format(
should_block_user=should_block_user,
user_id=user_id,
course_id=course_id,
exam_id=attempt['proctored_exam']['id'],
attempt_id=attempt_id,
error_detail=detail
)
)
elif action == 'decline':
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@edx/edx-proctoring",
"//": "Be sure to update the version number in edx_proctoring/__init__.py",
"//": "Note that the version format is slightly different than that of the Python version when using prereleases.",
"version": "3.8.7",
"version": "3.8.8",
"main": "edx_proctoring/static/index.js",
"scripts":{
"test":"gulp test"
Expand Down

0 comments on commit 1444ca4

Please sign in to comment.