Module: Aptible::CLI::Subcommands::Maintenance

Included in:
Agent
Defined in:
lib/aptible/cli/subcommands/maintenance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/aptible/cli/subcommands/maintenance.rb', line 5

def self.included(thor)
  thor.class_eval do
    include Helpers::Environment
    include Helpers::Maintenance
    include Helpers::Token

    desc 'maintenance:apps',
         'List Apps impacted by maintenance schedules where '\
         'restarts are required'
    option :environment
    define_method 'maintenance:apps' do
      found_maintenance = false
      m = maintenance_apps
      Formatter.render(Renderer.current) do |root|
        root.grouped_keyed_list(
          { 'environment' => 'handle' },
          'label'
        ) do |node|
          scoped_environments(options).each do ||
            m.select { |app| app..id == .id }
             .each do |app|
              next unless app.maintenance_deadline
              found_maintenance = true
              node.object do |n|
                ResourceFormatter.inject_maintenance(
                  n,
                  'aptible restart --app',
                  app,
                  
                )
              end
            end
          end
        end
      end
      if found_maintenance
        explanation 'app'
      else
        no_maintenances 'app'
      end
    end
    desc 'maintenance:dbs',
         'List Databases impacted by maintenance schedules where '\
         'restarts are required'
    option :environment
    define_method 'maintenance:dbs' do
      found_maintenance = false
      m = maintenance_databases
      Formatter.render(Renderer.current) do |root|
        root.grouped_keyed_list(
          { 'environment' => 'handle' },
          'label'
        ) do |node|
          scoped_environments(options).each do ||
            m.select { |db| db..id == .id }
             .each do |db|
              next unless db.maintenance_deadline
              found_maintenance = true
              node.object do |n|
                ResourceFormatter.inject_maintenance(
                  n,
                  'aptible db:restart',
                  db,
                  
                )
              end
            end
          end
        end
      end
      if found_maintenance
        explanation 'database'
      else
        no_maintenances 'database'
      end
    end
  end
end

Instance Method Details

#explanation(resource_type) ⇒ Object



84
85
86
87
88
# File 'lib/aptible/cli/subcommands/maintenance.rb', line 84

def explanation(resource_type)
  CLI.logger.warn "\nYou may restart these #{resource_type}(s)"\
                  ' at any time, or Aptible will restart it'\
                  ' during the defined window.'
end

#no_maintenances(resource_type) ⇒ Object



90
91
92
93
# File 'lib/aptible/cli/subcommands/maintenance.rb', line 90

def no_maintenances(resource_type)
  CLI.logger.info "\nNo #{resource_type}s found affected "\
                  'by maintenance schedules.'
end