Class: MaintenanceMode

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/core/maintenance_mode.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

DOMAIN_WORKLOAD_UPDATE_MAX_POLL_ATTEMPTS =
30
DOMAIN_WORKLOAD_UPDATE_RETRY_WAIT_SECONDS =
1
DOMAIN_WORKLOAD_UPDATE_STEP_OPTIONS =
{
  retry_on_failure: true,
  # `with_retry` loops while `retry_count <= max_retry_count` starting from 0, so
  # total attempts == max_retry_count + 1. Subtract 1 so the bounded poll runs
  # exactly DOMAIN_WORKLOAD_UPDATE_MAX_POLL_ATTEMPTS times.
  max_retry_count: DOMAIN_WORKLOAD_UPDATE_MAX_POLL_ATTEMPTS - 1,
  wait: DOMAIN_WORKLOAD_UPDATE_RETRY_WAIT_SECONDS
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ MaintenanceMode

Returns a new instance of MaintenanceMode.



19
20
21
# File 'lib/core/maintenance_mode.rb', line 19

def initialize(command)
  @command = command
end

Instance Method Details

#disable!Object



42
43
44
45
46
47
48
49
# File 'lib/core/maintenance_mode.rb', line 42

def disable!
  if disabled?
    progress.puts("Maintenance mode is already disabled for app '#{config.app}'.")
    ensure_maintenance_workload_stopped
  else
    disable_maintenance_mode
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/core/maintenance_mode.rb', line 28

def disabled?
  validate_domain_exists!
  cp.domain_workload_matches?(domain_data, one_off_workload)
end

#enable!Object



33
34
35
36
37
38
39
40
# File 'lib/core/maintenance_mode.rb', line 33

def enable!
  if enabled?
    progress.puts("Maintenance mode is already enabled for app '#{config.app}'.")
    ensure_app_workloads_stopped
  else
    enable_maintenance_mode
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/core/maintenance_mode.rb', line 23

def enabled?
  validate_domain_exists!
  cp.domain_workload_matches?(domain_data, maintenance_workload)
end