Class: HastCI::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/hastci/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, api_base_url:, api_max_retries:, run_key:, worker_id:, commit_sha:, claim_batch_size:, heartbeat_interval:, seeding_timeout:, log_level:, debug: false) ⇒ Config

Returns a new instance of Config.

Raises:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/hastci/config.rb', line 78

def initialize(
  api_key:,
  api_base_url:,
  api_max_retries:,
  run_key:,
  worker_id:,
  commit_sha:,
  claim_batch_size:,
  heartbeat_interval:,
  seeding_timeout:,
  log_level:,
  debug: false
)
  raise ConfigurationError, "worker_id cannot be blank" if worker_id.nil? || worker_id.empty?
  raise ConfigurationError, "claim_batch_size must be positive" if claim_batch_size <= 0
  raise ConfigurationError, "heartbeat_interval must be positive" if heartbeat_interval <= 0
  raise ConfigurationError, "seeding_timeout must be positive" if seeding_timeout <= 0

  @api_key = api_key
  @api_base_url = api_base_url
  @api_max_retries = api_max_retries
  @run_key = run_key
  @worker_id = worker_id
  @commit_sha = commit_sha
  @claim_batch_size = claim_batch_size
  @heartbeat_interval = heartbeat_interval
  @seeding_timeout = seeding_timeout
  @log_level = normalize_log_level(log_level)
  @debug = debug
end

Instance Attribute Details

#api_base_urlObject (readonly)

Returns the value of attribute api_base_url.



17
18
19
# File 'lib/hastci/config.rb', line 17

def api_base_url
  @api_base_url
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



17
18
19
# File 'lib/hastci/config.rb', line 17

def api_key
  @api_key
end

#api_max_retriesObject (readonly)

Returns the value of attribute api_max_retries.



17
18
19
# File 'lib/hastci/config.rb', line 17

def api_max_retries
  @api_max_retries
end

#claim_batch_sizeObject (readonly)

Returns the value of attribute claim_batch_size.



17
18
19
# File 'lib/hastci/config.rb', line 17

def claim_batch_size
  @claim_batch_size
end

#commit_shaObject (readonly)

Returns the value of attribute commit_sha.



17
18
19
# File 'lib/hastci/config.rb', line 17

def commit_sha
  @commit_sha
end

#debugObject (readonly)

Returns the value of attribute debug.



17
18
19
# File 'lib/hastci/config.rb', line 17

def debug
  @debug
end

#heartbeat_intervalObject (readonly)

Returns the value of attribute heartbeat_interval.



17
18
19
# File 'lib/hastci/config.rb', line 17

def heartbeat_interval
  @heartbeat_interval
end

#log_levelObject (readonly)

Returns the value of attribute log_level.



17
18
19
# File 'lib/hastci/config.rb', line 17

def log_level
  @log_level
end

#run_keyObject (readonly)

Returns the value of attribute run_key.



17
18
19
# File 'lib/hastci/config.rb', line 17

def run_key
  @run_key
end

#seeding_timeoutObject (readonly)

Returns the value of attribute seeding_timeout.



17
18
19
# File 'lib/hastci/config.rb', line 17

def seeding_timeout
  @seeding_timeout
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



17
18
19
# File 'lib/hastci/config.rb', line 17

def worker_id
  @worker_id
end

Class Method Details

.load_from_env(env) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/hastci/config.rb', line 21

def self.load_from_env(env)
  if env["GITHUB_ACTIONS"] == "true"
    from_github_actions(env)
  else
    from_generic_ci(env)
  end
rescue KeyError => e
  raise ConfigurationError, "Missing required env var: #{e.key}"
end