Class: NetworkClient

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/packages/network_layer/client/network_client.rb

Constant Summary collapse

HTTPS_SCHEME =
'https'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NetworkClient

Returns a new instance of NetworkClient.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wingify/packages/network_layer/client/network_client.rb', line 31

def initialize(options = {})
  # options for threading
  @should_use_threading = options.key?(:enabled) ? options[:enabled] : Constants::SHOULD_USE_THREADING
  @thread_pool = Concurrent::ThreadPoolExecutor.new(
    # Minimum number of threads to keep alive in the pool
    min_threads: 1,
    # Maximum number of threads allowed in the pool, configurable via options or defaults to MAX_POOL_SIZE constant
    max_threads: options.key?(:max_pool_size) ? options[:max_pool_size] : Constants::MAX_POOL_SIZE,
    # Maximum number of tasks that can be queued when all threads are busy
    max_queue: options.key?(:max_queue_size) ? options[:max_queue_size] : Constants::MAX_QUEUE_SIZE,
    # When queue is full, execute task in the caller's thread rather than rejecting it
    fallback_policy: :caller_runs
  )
end

Instance Method Details

#get(request_model) ⇒ Object



54
55
56
# File 'lib/wingify/packages/network_layer/client/network_client.rb', line 54

def get(request_model)
  execute_with_retry(request_model, :get_request)
end

#get_should_use_threadingObject



50
51
52
# File 'lib/wingify/packages/network_layer/client/network_client.rb', line 50

def get_should_use_threading
  @should_use_threading
end

#get_thread_poolObject



46
47
48
# File 'lib/wingify/packages/network_layer/client/network_client.rb', line 46

def get_thread_pool
  @thread_pool
end

#post(request_model) ⇒ Object



58
59
60
# File 'lib/wingify/packages/network_layer/client/network_client.rb', line 58

def post(request_model)
  execute_with_retry(request_model, :post_request)
end