Sha256: 96a03cfe903aa983b94ec5f60bdec2e658ed99afe3b6310e75e6a57802d0a41a
Contents?: true
Size: 1.33 KB
Versions: 9
Compression:
Stored size: 1.33 KB
Contents
# A steady walker that tries 3 times each step module Restfulie module Client module Mikyung class SteadyStateWalker def move(goal, current, mikyung) step = goal.next_step(current, mikyung) raise UnableToAchieveGoalError, "No step was found for #{current}" unless step Common::Logger.logger.debug "Mikyung > next step will be #{step}" step = step.new if step.kind_of? Class try_to_execute(step, current, 3, mikyung) end private def try_to_execute(step, current, max_attempts, mikyung) raise "Unable to proceed when trying to analyze #{step.body}" if max_attempts == 0 resource = step raise "Step returned 'give up'" if resource.nil? if step.respond_to?(:execute) resource = step.execute(current, mikyung) end # TODO: should it really retry if it is not 200? Or only if it is on the 50x family? # for instance the result could be a 302 redirection unless resource.response.code == 200 try_to_execute(step, current, max_attempts-1, mikyung) else Common::Logger.logger.debug resource.response.body resource end end end end end end
Version data entries
9 entries across 9 versions & 2 rubygems