Commit 73bd46d7 by kimth

LMS must login before submitting to xqueue

parent faf3d2c3
...@@ -881,15 +881,15 @@ class CodeResponse(LoncapaResponse): ...@@ -881,15 +881,15 @@ class CodeResponse(LoncapaResponse):
'edX_student_response': submission} 'edX_student_response': submission}
# Submit request # Submit request
success = xqueue_interface.send_to_queue(header=xheader, error = xqueue_interface.send_to_queue(header=xheader,
body=json.dumps(contents)) body=json.dumps(contents))
cmap = CorrectMap() cmap = CorrectMap()
if success: if error:
cmap.set(self.answer_id, msg='Unable to deliver your submission to grader! Please try again later')
else:
# Non-null CorrectMap['queuekey'] indicates that the problem has been queued # Non-null CorrectMap['queuekey'] indicates that the problem has been queued
cmap.set(self.answer_id, queuekey=queuekey, msg='Submitted to grader') 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 return cmap
......
...@@ -5,7 +5,8 @@ import json ...@@ -5,7 +5,8 @@ import json
import requests import requests
# TODO: Collection of parameters to be hooked into rest of edX system # TODO: Collection of parameters to be hooked into rest of edX system
XQUEUE_SUBMIT_URL = 'http://xqueue.edx.org/xqueue/submit/' XQUEUE_LMS_AUTH = ('LMS','PaloAltoCA') # (username, password)
XQUEUE_SUBMIT_URL = 'http://xqueue.edx.org'
def upload_files_to_s3(): def upload_files_to_s3():
print ' THK: xqueue_interface.upload_files_to_s3' print ' THK: xqueue_interface.upload_files_to_s3'
...@@ -35,21 +36,42 @@ def send_to_queue(header, body, xqueue_url=None): ...@@ -35,21 +36,42 @@ def send_to_queue(header, body, xqueue_url=None):
body: Serialized data for the receipient behind the queueing service. The operation of body: Serialized data for the receipient behind the queueing service. The operation of
xqueue is agnostic to the contents of 'body' xqueue is agnostic to the contents of 'body'
Returns a 'success' flag indicating successful submission Returns an 'error' flag indicating error in xqueue transaction
''' '''
if xqueue_url is None: if xqueue_url is None:
xqueue_url = XQUEUE_SUBMIT_URL xqueue_url = XQUEUE_SUBMIT_URL
# Contact queue server # First, we login with our credentials
#------------------------------------------------------------
s = requests.session()
try:
r = s.post(xqueue_url+'/xqueue/login/', data={ 'username': XQUEUE_LMS_AUTH[0],
'password': XQUEUE_LMS_AUTH[1] })
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)
# Xqueue responses are JSON-serialized dicts
xreply = json.loads(r.text)
return_code = xreply['return_code']
if return_code: # Nonzero return code from xqueue indicates error
print ' Error in queue_interface.send_to_queue: %s' % xreply['content']
return 1 # Error
# Next, we can make a queueing request
#------------------------------------------------------------
payload = {'xqueue_header': header, payload = {'xqueue_header': header,
'xqueue_body' : body} 'xqueue_body' : body}
try: try:
r = requests.post(xqueue_url, data=payload) # Send request
r = s.post(xqueue_url+'/xqueue/submit/', data=payload)
except Exception as err: except Exception as err:
msg = 'Error in xqueue_interface.send_to_queue %s: Cannot connect to server url=%s' % (err, xqueue_url) msg = 'Error in xqueue_interface.send_to_queue %s: Cannot connect to server url=%s' % (err, xqueue_url)
raise Exception(msg) raise Exception(msg)
# Xqueue responses are JSON-serialized dicts
xreply = json.loads(r.text) xreply = json.loads(r.text)
return_code = xreply['return_code']
if return_code:
print ' Error in queue_interface.send_to_queue: %s' % xreply['content']
return xreply['return_code'] == 0 # return_code == 0 from xqueue indicates successful submission return return_code
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment