Class: PgBouncerHero::DatabaseController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pg_bouncer_hero/database_controller.rb

Constant Summary collapse

DATABASE_ADMIN_ACTIONS =
%i[pause_database reconnect_database wait_close_database resume_database].freeze
MONITORING_ACTIONS =
%i[databases stats pools clients servers users conf state].freeze

Instance Method Summary collapse

Instance Method Details

#clientsObject



37
38
39
40
41
42
43
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 37

def clients
  if @database.connection
    @clients = @database.clients
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#confObject



61
62
63
64
65
66
67
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 61

def conf
  if @database.connection
    @conf = @database.conf
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#databasesObject



13
14
15
16
17
18
19
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 13

def databases
  if @database.connection
    @dbs = @database.databases
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#pause_databaseObject



89
90
91
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 89

def pause_database
  execute_database_admin_command(:pause, "paused")
end

#poolsObject



29
30
31
32
33
34
35
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 29

def pools
  if @database.connection
    @pools = @database.pools
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#reconnect_databaseObject



93
94
95
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 93

def reconnect_database
  execute_database_admin_command(:reconnect, "asked to reconnect released server connections")
end

#reloadObject



77
78
79
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 77

def reload
  execute_admin_command(:reload, "reloaded")
end

#resumeObject



85
86
87
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 85

def resume
  execute_admin_command(:resume, "resumed")
end

#resume_databaseObject



101
102
103
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 101

def resume_database
  execute_database_admin_command(:resume, "resumed")
end

#serversObject



45
46
47
48
49
50
51
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 45

def servers
  if @database.connection
    @servers = @database.servers
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#shutdownObject



105
106
107
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 105

def shutdown
  execute_admin_command(:shutdown, "asked to shut down after its clients disconnect", :wait_for_clients)
end

#stateObject



69
70
71
72
73
74
75
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 69

def state
  if @admin_state
    @state = @admin_state
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#statsObject



21
22
23
24
25
26
27
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 21

def stats
  if @database.connection
    @stats = @database.stats
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#summaryObject



10
11
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 10

def summary
end

#suspendObject



81
82
83
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 81

def suspend
  execute_admin_command(:suspend, "suspended")
end

#usersObject



53
54
55
56
57
58
59
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 53

def users
  if @database.connection
    @users = @database.users
  else
    flash[:error] = "#{@database.name} does not look online."
  end
end

#wait_close_databaseObject



97
98
99
# File 'app/controllers/pg_bouncer_hero/database_controller.rb', line 97

def wait_close_database
  execute_database_admin_command(:wait_close, "confirmed all marked server connections closed")
end