Class: WarmBlanket::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/warm_blanket/orchestrator.rb

Overview

Orchestrates threads to wait for the port to open and to perform the warmup requests

Constant Summary collapse

DEFAULT_HEADERS =
{
  'X-Forwarded-Proto': 'https',
  'X-Request-Id': 'WarmBlanket',
  'X-Client-Id': 'WarmBlanket',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(requester_factory: Requester, wait_for_port_factory: WaitForPort, logger: WarmBlanket.config.logger, endpoints: WarmBlanket.config.endpoints, hostname: 'localhost', port: WarmBlanket.config.port, warmup_threads: WarmBlanket.config.warmup_threads, warmup_time_seconds: WarmBlanket.config.warmup_time_seconds) ⇒ Orchestrator

Returns a new instance of Orchestrator.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/warm_blanket/orchestrator.rb', line 47

def initialize(
  requester_factory: Requester,
  wait_for_port_factory: WaitForPort,
  logger: WarmBlanket.config.logger,
  endpoints: WarmBlanket.config.endpoints,
  hostname: 'localhost',
  port: WarmBlanket.config.port,
  warmup_threads: WarmBlanket.config.warmup_threads,
  warmup_time_seconds: WarmBlanket.config.warmup_time_seconds
)
  raise "Warmup threads cannot be less than 1 (got #{warmup_threads})" if warmup_threads < 1

  @requester_factory = requester_factory
  @wait_for_port_factory = wait_for_port_factory
  @logger = logger
  @endpoints = endpoints
  @hostname = hostname
  @port = port
  @warmup_threads = warmup_threads
  @warmup_deadline = Time.now + warmup_time_seconds
end

Instance Method Details

#callObject



69
70
71
72
73
74
# File 'lib/warm_blanket/orchestrator.rb', line 69

def call
  safely_spawn_thread do
    logger.debug 'Started orchestrator thread'
    orchestrate
  end
end