Skip to content

Commit

Permalink
Fixed @Halt
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Xia committed Feb 23, 2012
1 parent bfd6be4 commit 934d154
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions lib/coursera_client.rb
Expand Up @@ -136,26 +136,43 @@ def decode_submission(submission)
end

def each_submission
# Loop forever
if @halt
while True
@autograders.keys.each do |assignment_part_sid|
logger.info assignment_part_sid
if @controller.get_queue_length(assignment_part_sid) == 0
next
end
result = @controller.get_pending_submission(assignment_part_sid)
next if result.nil?
logger.info " received submission: #{result['submission_metadata']['submission_id']}"
logger.debug result['submission_metadata']

yield assignment_part_sid, result
end
end
else
# Iterate round robin through assignment parts until all queues are empty
# parameterize this differently
# Unless if @halt is false
while @autograders.size > 0 || !@halt
to_delete = []
@autograders.keys.each do |assignment_part_sid|
logger.info assignment_part_sid
if @controller.get_queue_length(assignment_part_sid) == 0
logger.info " queue length 0; removing"
to_delete << assignment_part_sid
next
while @autograders.size > 0
to_delete = []
@autograders.keys.each do |assignment_part_sid|
logger.info assignment_part_sid
if @controller.get_queue_length(assignment_part_sid) == 0
logger.info " queue length 0; removing"
to_delete << assignment_part_sid
next
end
result = @controller.get_pending_submission(assignment_part_sid)
next if result.nil?
logger.info " received submission: #{result['submission_metadata']['submission_id']}"
logger.debug result['submission_metadata']

yield assignment_part_sid, result
end
result = @controller.get_pending_submission(assignment_part_sid)
next if result.nil?
logger.info " received submission: #{result['submission_metadata']['submission_id']}"
logger.debug result['submission_metadata']

yield assignment_part_sid, result
@autograders.delete_if{|key,value| to_delete.include? key}
end
@autograders.delete_if{|key,value| to_delete.include? key}
end
end

Expand Down

0 comments on commit 934d154

Please sign in to comment.