exponentially back off sleep if the Octokit::Forbidden error is seen

This commit is contained in:
Andrew Waage 2016-10-07 16:28:02 -07:00
parent 72dc650b0e
commit aa0d7e8d17

View File

@ -280,19 +280,35 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
# #
# @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block # @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block
def check_github_response def check_github_response
attempt = 1
begin begin
value = yield value = yield
rescue Octokit::Unauthorized => e rescue Octokit::Unauthorized => e
Helper.log.error e.message Helper.log.error e.message
abort "Error: wrong GitHub token" abort "Error: wrong GitHub token"
rescue Octokit::Forbidden => e rescue Octokit::Forbidden => e
attempt += 1
sleep_time = exp_backoff(attempt)
Helper.log.warn("sleeping #{sleep_time} second")
sleep(sleep_time)
Helper.log.warn e.message Helper.log.warn e.message
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
Helper.log.warn @client.rate_limit Helper.log.warn @client.rate_limit
retry
end end
value value
end end
# Returns the exponential backoff (seconds) for this attempt number
#
# @param [Integer] attempt the attempt number
# @return [Integer] Exponential backoff seconds
def exp_backoff(attempt)
(2 ** attempt - 1) / 2
end
# Print specified line on the same string # Print specified line on the same string
# #
# @param [String] log_string # @param [String] log_string