Upload to xqueue
This commit is contained in:
@@ -848,12 +848,13 @@ class CodeResponse(LoncapaResponse):
|
||||
|
||||
def get_score(self, student_answers):
|
||||
try:
|
||||
submission = student_answers[self.answer_id]
|
||||
submission = student_answers[self.answer_id] # Note that submission can be a file
|
||||
except Exception as err:
|
||||
log.error('Error in CodeResponse %s: cannot get student answer for %s; student_answers=%s' % (err, self.answer_id, student_answers))
|
||||
log.error('Error in CodeResponse %s: cannot get student answer for %s; student_answers=%s' %
|
||||
(err, self.answer_id, convert_files_to_filenames(student_answers)))
|
||||
raise Exception(err)
|
||||
|
||||
self.context.update({'submission': unicode(submission)}) # Submission could be a file
|
||||
self.context.update({'submission': unicode(submission)})
|
||||
|
||||
# Prepare xqueue request
|
||||
#------------------------------------------------------------
|
||||
@@ -873,8 +874,13 @@ class CodeResponse(LoncapaResponse):
|
||||
'edX_student_response': unicode(submission)}
|
||||
|
||||
# Submit request
|
||||
error = xqueue_interface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
if hasattr(submission, 'read'): # Test for whether submission is a file
|
||||
error = xqueue_interface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents),
|
||||
file_to_upload=submission)
|
||||
else:
|
||||
error = xqueue_interface.send_to_queue(header=xheader,
|
||||
body=json.dumps(contents))
|
||||
|
||||
cmap = CorrectMap()
|
||||
if error:
|
||||
|
||||
@@ -37,7 +37,7 @@ def make_xheader(lms_callback_url, lms_key, queue_name):
|
||||
'queue_name': queue_name })
|
||||
|
||||
|
||||
def send_to_queue(header, body, xqueue_url=None):
|
||||
def send_to_queue(header, body, file_to_upload=None, xqueue_url=None):
|
||||
'''
|
||||
Submit a request to xqueue.
|
||||
|
||||
@@ -46,6 +46,8 @@ 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'
|
||||
|
||||
file_to_upload: File object to be uploaded to xqueue along with queue request
|
||||
|
||||
Returns an 'error' flag indicating error in xqueue transaction
|
||||
'''
|
||||
if xqueue_url is None:
|
||||
@@ -72,9 +74,13 @@ def send_to_queue(header, body, xqueue_url=None):
|
||||
#------------------------------------------------------------
|
||||
payload = {'xqueue_header': header,
|
||||
'xqueue_body' : body}
|
||||
|
||||
files = None
|
||||
if file_to_upload is not None:
|
||||
files = { file_to_upload.name: file_to_upload }
|
||||
|
||||
try:
|
||||
# Send request
|
||||
r = s.post(xqueue_url+'/xqueue/submit/', data=payload)
|
||||
r = s.post(xqueue_url+'/xqueue/submit/', data=payload, files=files)
|
||||
except Exception as err:
|
||||
msg = 'Error in xqueue_interface.send_to_queue %s: Cannot connect to server url=%s' % (err, xqueue_url)
|
||||
raise Exception(msg)
|
||||
|
||||
Reference in New Issue
Block a user