Class: ConfCtl::HealthChecks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/health_checks/base.rb

Direct Known Subclasses

RunCommand, Systemd::Properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Base

Returns a new instance of Base.

Parameters:



10
11
12
13
# File 'lib/confctl/health_checks/base.rb', line 10

def initialize(machine)
  @machine = machine
  @errors = []
end

Instance Attribute Details

#errorsArray<String> (readonly)

Returns:

  • (Array<String>)


7
8
9
# File 'lib/confctl/health_checks/base.rb', line 7

def errors
  @errors
end

#machineMachine (readonly)

Returns:



4
5
6
# File 'lib/confctl/health_checks/base.rb', line 4

def machine
  @machine
end

Instance Method Details

#descriptionObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/confctl/health_checks/base.rb', line 38

def description
  raise NotImplementedError
end

#messageObject



42
43
44
# File 'lib/confctl/health_checks/base.rb', line 42

def message
  @errors.join('; ')
end

#run {|number, errors| ... } ⇒ Object

Yield Parameters:

  • number (Integer)

    of attempts

  • errors (Array)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/confctl/health_checks/base.rb', line 17

def run
  @started_at = Time.now
  now = @started_at
  attempt = 1

  until timeout?(now)
    @errors.clear
    run_check
    break if successful?

    yield(attempt, errors) if block_given?
    sleep(cooldown)
    attempt += 1
    now = Time.now
  end
end

#successful?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/confctl/health_checks/base.rb', line 34

def successful?
  @errors.empty?
end