lib/github_issue_stats.rb
def sleep_before_api_call()
    @logger.debug "Calculating sleep period for next search API call"

    rate_limit_data = @client.get("https://api.github.com/rate_limit")

    if rate_limit_data[:resources][:core][:remaining] <= 2
      reset_timestamp = rate_limit_data[:resources][:core][:reset]
      sleep_seconds = reset_timestamp - Time.now.to_i + 3
      @logger.warn "Remaining regular API rate limit is close to 0, sleeping for #{sleep_seconds} seconds."
      sleep(sleep_seconds)
elsif rate_limit_data[:resources][:search][:remaining] <= 2
      reset_timestamp = rate_limit_data[:resources][:search][:reset]
      sleep_seconds = reset_timestamp - Time.now.to_i + 3
      @logger.warn "Remaining search API rate limit is close to 0, sleeping for #{sleep_seconds} seconds."
      sleep(sleep_seconds)
    elsif
      sleep(1)
    end
  end
#
# Computes the required sleep period to avoid hitting the API rate limits
#
Computes the required sleep period to avoid hitting the API rate limits
Computes the required sleep period to avoid hitting the API rate limits
def sleep_before_api_call()
    @logger.debug "Calculating sleep period for next search API call"
    rate_limit_data = @client.get("https://api.github.com/rate_limit")
    if rate_limit_data[:resources][:core][:remaining] <= 2
      reset_timestamp = rate_limit_data[:resources][:core][:reset]
      sleep_seconds = reset_timestamp - Time.now.to_i + 3
      @logger.warn "Remaining regular API rate limit is close to 0, sleeping for #{sleep_seconds} seconds."
      sleep(sleep_seconds)
elsif rate_limit_data[:resources][:search][:remaining] <= 2
      reset_timestamp = rate_limit_data[:resources][:search][:reset]
      sleep_seconds = reset_timestamp - Time.now.to_i + 3
      @logger.warn "Remaining search API rate limit is close to 0, sleeping for #{sleep_seconds} seconds."
      sleep(sleep_seconds)
    elsif
      sleep(1)
    end
  end
def sleep_before_api_call ( ) @logger . debug "Calculating sleep period for next search API call" rate_limit_data = @client . get ( "https://api.github.com/rate_limit" ) if rate_limit_data [ :resources ] [ :core ] [ :remaining ] <= 2 reset_timestamp = rate_limit_data [ :resources ] [ :core ] [ :reset ] sleep_seconds = reset_timestamp - Time . now . to_i + 3 @logger . warn "Remaining regular API rate limit is close to 0, sleeping for #{sleep_seconds} seconds." sleep ( sleep_seconds ) elsif rate_limit_data [ :resources ] [ :search ] [ :remaining ] <= 2 reset_timestamp = rate_limit_data [ :resources ] [ :search ] [ :reset ] sleep_seconds = reset_timestamp - Time . now . to_i + 3 @logger . warn "Remaining search API rate limit is close to 0, sleeping for #{sleep_seconds} seconds." sleep ( sleep_seconds ) elsif sleep ( 1 ) end end
Computes the required sleep period to avoid hitting the API rate limits
Computes the required sleep period to avoid hitting the API rate limits