lib/coursemology/evaluator/client.rb in coursemology-evaluator-0.1.3 vs lib/coursemology/evaluator/client.rb in coursemology-evaluator-0.1.4
- old
+ new
@@ -13,28 +13,31 @@
@terminate = one_shot
end
def run
Signal.trap('SIGTERM', method(:on_sig_term))
+ loop(&method(:client_loop))
+ end
- loop do
- evaluations = allocate_evaluations
+ private
- if evaluations && !evaluations.empty?
- on_allocate(evaluations)
- else
- # :nocov:
- # This sleep might not be triggered in the specs, because interruptions to the thread is
- # nondeterministically run by the OS scheduler.
- sleep(1.minute)
- # :nocov:
- end
+ # Performs one iteration of the client loop.
+ def client_loop
+ evaluations = allocate_evaluations
+ if evaluations && !evaluations.empty?
+ on_allocate(evaluations)
+ else
+ raise StopIteration if @terminate
- break if @terminate
+ # :nocov:
+ # This sleep might not be triggered in the specs, because interruptions to the thread is
+ # nondeterministically run by the OS scheduler.
+ sleep(1.minute)
+ # :nocov:
end
- end
- private
+ raise StopIteration if @terminate
+ end
# Requests evaluations from the server.
#
# @return [Array<Coursemology::Evaluator::Models::ProgrammingEvaluation>] The evaluations
# retrieved from the server.