Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
03fd4f9b
Commit
03fd4f9b
authored
Oct 08, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatting in xqueue_interface.py
parent
f5787390
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
16 deletions
+18
-16
common/lib/capa/capa/xqueue_interface.py
+18
-16
No files found.
common/lib/capa/capa/xqueue_interface.py
View file @
03fd4f9b
...
...
@@ -12,7 +12,7 @@ dateformat = '%Y%m%d%H%M%S'
def
make_hashkey
(
seed
):
'''
Generate a string key by hashing
Generate a string key by hashing
'''
h
=
hashlib
.
md5
()
h
.
update
(
str
(
seed
))
...
...
@@ -20,27 +20,27 @@ def make_hashkey(seed):
def
make_xheader
(
lms_callback_url
,
lms_key
,
queue_name
):
'''
"""
Generate header for delivery and reply of queue request.
Xqueue header is a JSON-serialized dict:
{ 'lms_callback_url': url to which xqueue will return the request (string),
'lms_key': secret key used by LMS to protect its state (string),
'lms_key': secret key used by LMS to protect its state (string),
'queue_name': designate a specific queue within xqueue server, e.g. 'MITx-6.00x' (string)
}
'''
"""
return
json
.
dumps
({
'lms_callback_url'
:
lms_callback_url
,
'lms_key'
:
lms_key
,
'queue_name'
:
queue_name
})
def
parse_xreply
(
xreply
):
'''
"""
Parse the reply from xqueue. Messages are JSON-serialized dict:
{ 'return_code': 0 (success), 1 (fail)
'content': Message from xqueue (string)
}
'''
"""
try
:
xreply
=
json
.
loads
(
xreply
)
except
ValueError
,
err
:
...
...
@@ -61,11 +61,11 @@ class XQueueInterface(object):
self
.
url
=
url
self
.
auth
=
django_auth
self
.
session
=
requests
.
session
(
auth
=
requests_auth
)
def
send_to_queue
(
self
,
header
,
body
,
files_to_upload
=
None
):
'''
"""
Submit a request to xqueue.
header: JSON-serialized dict in the format described in 'xqueue_interface.make_xheader'
body: Serialized data for the receipient behind the queueing service. The operation of
...
...
@@ -74,14 +74,16 @@ class XQueueInterface(object):
files_to_upload: List of file objects to be uploaded to xqueue along with queue request
Returns (error_code, msg) where error_code != 0 indicates an error
'''
"""
# Attempt to send to queue
(
error
,
msg
)
=
self
.
_send_to_queue
(
header
,
body
,
files_to_upload
)
if
error
and
(
msg
==
'login_required'
):
# Log in, then try again
# Log in, then try again
if
error
and
(
msg
==
'login_required'
):
self
.
_login
()
if
files_to_upload
is
not
None
:
for
f
in
files_to_upload
:
# Need to rewind file pointers
# Need to rewind file pointers
for
f
in
files_to_upload
:
f
.
seek
(
0
)
(
error
,
msg
)
=
self
.
_send_to_queue
(
header
,
body
,
files_to_upload
)
...
...
@@ -91,18 +93,18 @@ class XQueueInterface(object):
def
_login
(
self
):
payload
=
{
'username'
:
self
.
auth
[
'username'
],
'password'
:
self
.
auth
[
'password'
]
}
return
self
.
_http_post
(
self
.
url
+
'/xqueue/login/'
,
payload
)
return
self
.
_http_post
(
self
.
url
+
'/xqueue/login/'
,
payload
)
def
_send_to_queue
(
self
,
header
,
body
,
files_to_upload
):
payload
=
{
'xqueue_header'
:
header
,
'xqueue_body'
:
body
}
files
=
{}
files
=
{}
if
files_to_upload
is
not
None
:
for
f
in
files_to_upload
:
files
.
update
({
f
.
name
:
f
})
return
self
.
_http_post
(
self
.
url
+
'/xqueue/submit/'
,
payload
,
files
=
files
)
return
self
.
_http_post
(
self
.
url
+
'/xqueue/submit/'
,
payload
,
files
=
files
)
def
_http_post
(
self
,
url
,
data
,
files
=
None
):
...
...
@@ -111,7 +113,7 @@ class XQueueInterface(object):
except
requests
.
exceptions
.
ConnectionError
,
err
:
log
.
error
(
err
)
return
(
1
,
'cannot connect to server'
)
if
r
.
status_code
not
in
[
200
]:
return
(
1
,
'unexpected HTTP status code [
%
d]'
%
r
.
status_code
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment