Class: Gitlab::GithubImport::ClientPool

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/client_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(token_pool:, per_page:, parallel:, host: nil) ⇒ ClientPool

Returns a new instance of ClientPool.



8
9
10
11
12
13
# File 'lib/gitlab/github_import/client_pool.rb', line 8

def initialize(token_pool:, per_page:, parallel:, host: nil)
  @token_pool = token_pool
  @host = host
  @per_page = per_page
  @parallel = parallel
end

Instance Method Details

#best_clientObject

Returns the client with the most remaining requests, or the client with the closest rate limit reset time, if all clients are rate limited.



17
18
19
20
21
22
23
# File 'lib/gitlab/github_import/client_pool.rb', line 17

def best_client
  clients_with_requests_remaining = clients.select(&:requests_remaining?)

  return clients_with_requests_remaining.max_by(&:remaining_requests) if clients_with_requests_remaining.any?

  clients.min_by(&:rate_limit_resets_in)
end