CodeResponse does basic error handling from xqueue submission
This commit is contained in:
@@ -881,12 +881,15 @@ class CodeResponse(LoncapaResponse):
|
||||
'edX_student_response': submission}
|
||||
|
||||
# Submit request
|
||||
xqueue_interface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
success = xqueue_interface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
|
||||
# Non-null CorrectMap['queuekey'] indicates that the problem has been queued
|
||||
cmap = CorrectMap()
|
||||
cmap.set(self.answer_id, queuekey=queuekey, msg='Submitted to queue')
|
||||
cmap = CorrectMap()
|
||||
if success:
|
||||
# Non-null CorrectMap['queuekey'] indicates that the problem has been queued
|
||||
cmap.set(self.answer_id, queuekey=queuekey, msg='Submitted to grader')
|
||||
else:
|
||||
cmap.set(self.answer_id, msg='Unable to deliver submission to grader! Please try again later')
|
||||
|
||||
return cmap
|
||||
|
||||
@@ -908,7 +911,7 @@ class CodeResponse(LoncapaResponse):
|
||||
self.context['correct'][0] = admap[ad]
|
||||
|
||||
# Replace 'oldcmap' with new grading results if queuekey matches.
|
||||
# If queuekey does not match, we keep waiting for the score_msg whose key actually matchs
|
||||
# If queuekey does not match, we keep waiting for the score_msg whose key actually matches
|
||||
if oldcmap.is_right_queuekey(self.answer_id, queuekey):
|
||||
msg = rxml.find('message').text.replace(' ', ' ')
|
||||
oldcmap.set(self.answer_id, correctness=self.context['correct'][0], msg=msg, queuekey=None) # Queuekey is consumed
|
||||
|
||||
@@ -35,6 +35,7 @@ def send_to_queue(header, body, xqueue_url=None):
|
||||
body: Serialized data for the receipient behind the queueing service. The operation of
|
||||
xqueue is agnostic to the contents of 'body'
|
||||
|
||||
Returns a 'success' flag indicating successful submission
|
||||
'''
|
||||
if xqueue_url is None:
|
||||
xqueue_url = XQUEUE_SUBMIT_URL
|
||||
@@ -48,4 +49,7 @@ def send_to_queue(header, body, xqueue_url=None):
|
||||
msg = 'Error in xqueue_interface.send_to_queue %s: Cannot connect to server url=%s' % (err, xqueue_url)
|
||||
raise Exception(msg)
|
||||
|
||||
#print r.text
|
||||
# Xqueue responses are JSON-serialized dicts
|
||||
xreply = json.loads(r.text)
|
||||
|
||||
return xreply['return_code'] == 0 # return_code == 0 from xqueue indicates successful submission
|
||||
|
||||
Reference in New Issue
Block a user