Class: Specbandit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/specbandit/configuration.rb

Constant Summary collapse

DEFAULT_REDIS_URL =
'redis://localhost:6379'
DEFAULT_BATCH_SIZE =
5
DEFAULT_KEY_TTL =

A single TTL governs every key specbandit writes: the shared queue, its published marker, the per-runner rerun key and the failed key. It defaults to 1 week because re-runs can happen hours or days after the original run, and the rerun key + published marker must still be alive when they do.

604_800
DEFAULT_ADAPTER =

1 week in seconds

'cli'
DEFAULT_REDIS_MAX_ATTEMPTS =

Redis connection resilience. Redis is a best-effort coordination store for a distributed test run, and CI runners can sit a WAN hop away from it (e.g. cross-datacenter mesh), so a transient blip must not red the build. We retry a handful of times with capped exponential backoff, and give the underlying client explicit connect/read/write timeouts + reconnects rather than relying on library defaults.

5
DEFAULT_REDIS_CONNECT_TIMEOUT =
3.0
DEFAULT_REDIS_TIMEOUT =
5.0
DEFAULT_REDIS_RECONNECT_ATTEMPTS =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/specbandit/configuration.rb', line 32

def initialize
  @redis_url = ENV.fetch('SPECBANDIT_REDIS_URL', DEFAULT_REDIS_URL)
  @batch_size = Integer(ENV.fetch('SPECBANDIT_BATCH_SIZE', DEFAULT_BATCH_SIZE))
  @key = ENV.fetch('SPECBANDIT_KEY', nil)
  @rspec_opts = parse_rspec_opts(ENV.fetch('SPECBANDIT_RSPEC_OPTS', nil))
  @key_ttl = Integer(ENV.fetch('SPECBANDIT_KEY_TTL', DEFAULT_KEY_TTL))
  @key_rerun = ENV.fetch('SPECBANDIT_KEY_RERUN', nil)
  @verbose = env_truthy?('SPECBANDIT_VERBOSE')
  @adapter = ENV.fetch('SPECBANDIT_ADAPTER', DEFAULT_ADAPTER)
  @command = ENV.fetch('SPECBANDIT_COMMAND', nil)
  @command_opts = parse_space_separated(ENV.fetch('SPECBANDIT_COMMAND_OPTS', nil))
  @key_failed = ENV.fetch('SPECBANDIT_KEY_FAILED', nil)
  @report = ENV.fetch('SPECBANDIT_REPORT', nil)

  @redis_max_attempts = Integer(ENV.fetch('SPECBANDIT_REDIS_MAX_ATTEMPTS', DEFAULT_REDIS_MAX_ATTEMPTS))
  @redis_connect_timeout = Float(ENV.fetch('SPECBANDIT_REDIS_CONNECT_TIMEOUT', DEFAULT_REDIS_CONNECT_TIMEOUT))
  @redis_timeout = Float(ENV.fetch('SPECBANDIT_REDIS_TIMEOUT', DEFAULT_REDIS_TIMEOUT))
  @redis_reconnect_attempts = Integer(ENV.fetch('SPECBANDIT_REDIS_RECONNECT_ATTEMPTS', DEFAULT_REDIS_RECONNECT_ATTEMPTS))
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def adapter
  @adapter
end

#batch_sizeObject

Returns the value of attribute batch_size.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def batch_size
  @batch_size
end

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def command
  @command
end

#command_optsObject

Returns the value of attribute command_opts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def command_opts
  @command_opts
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key
  @key
end

#key_failedObject

Returns the value of attribute key_failed.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_failed
  @key_failed
end

#key_rerunObject

Returns the value of attribute key_rerun.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_rerun
  @key_rerun
end

#key_ttlObject

Returns the value of attribute key_ttl.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_ttl
  @key_ttl
end

#redis_connect_timeoutObject

Returns the value of attribute redis_connect_timeout.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_connect_timeout
  @redis_connect_timeout
end

#redis_max_attemptsObject

Returns the value of attribute redis_max_attempts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_max_attempts
  @redis_max_attempts
end

#redis_reconnect_attemptsObject

Returns the value of attribute redis_reconnect_attempts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_reconnect_attempts
  @redis_reconnect_attempts
end

#redis_timeoutObject

Returns the value of attribute redis_timeout.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_timeout
  @redis_timeout
end

#redis_urlObject

Returns the value of attribute redis_url.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_url
  @redis_url
end

#reportObject

Returns the value of attribute report.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def report
  @report
end

#rspec_optsObject

Returns the value of attribute rspec_opts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def rspec_opts
  @rspec_opts
end

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#validate!Object

Raises:



52
53
54
55
56
57
# File 'lib/specbandit/configuration.rb', line 52

def validate!
  raise Error, 'key is required (set via --key or SPECBANDIT_KEY)' if key.nil? || key.empty?
  raise Error, 'batch_size must be a positive integer' unless batch_size.positive?
  raise Error, 'key_ttl must be a positive integer' unless key_ttl.positive?
  raise Error, 'redis_max_attempts must be a positive integer' unless redis_max_attempts.positive?
end