Skip to content

Commit

Permalink
Merge pull request #23 from rightscale/CF-2242_KHR_retry_after_strategy
Browse files Browse the repository at this point in the history
CF-2242 - added new retry strategy to handle 'Retry-After' header
  • Loading branch information
Anatoli Liotych authored Jan 9, 2017
2 parents 44157ee + 1ca0573 commit 84b1364
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/base/api_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def self.set_routine(*new_routines)
# A set of options for how retry behavior works.
# available retry options
# :count => Integer # number of retry attempts
# :strategy => Symbol # retry strategy[ :exponentional (default), :full_jitter, :equal_jitter, :decorrelated_jitter]
# :strategy => Symbol # retry strategy[ :exponentional (default), :full_jitter, :equal_jitter, :decorrelated_jitter, :retry_after]
# :reiteration_time => Integer # maximum amount of time to allow for retries
# :sleep_time => Integer # base sleep time in seconds, actual sleep time depends on strategy and count
#
Expand Down
2 changes: 2 additions & 0 deletions lib/base/routines/retry_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def process
when :decorrelated_jitter
# sleep = random_between(base, previous_sleep * 3)
rand * (3*previous_sleep - base_sleep_time) + base_sleep_time
when :retry_after
Array((@data[:response][:instance].headers || {})["Retry-After"]).first.to_i
else # default behavior, exponential
base_sleep_time * 2**(attempt-1)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/base/routines/routine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module CloudApi
#
# The routine is a very simple object that does a simple task in the API call processing stack
# and exits. In most cases a single routine knows nothing about any other routines. It just
# takes incoming params from @data hash, processes it and stores back to the @adata attribute.
# takes incoming params from @data hash, processes it and stores back to the @data attribute.
#
class Routine
attr_reader :data
Expand Down

0 comments on commit 84b1364

Please sign in to comment.