Class: Reptile::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/reptile/status.rb

Overview

The Status class is responsible for asking a slave database for its status is, parsing the result, and returning the appropiate status code.

This class also allows you to convert a status code to a friendly message the corresponds to that status.

Constant Summary collapse

SQL_THREAD_DOWN =

Status code indicating the SQL thread has stopped running.

'sql_thread_down'
IO_THREAD_DOWN =

Status code indicating the IO thread has stopped running.

'io_thread_down'
SLAVE_DOWN =

Status code indicating that the slave has stopped replicating.

'slave_down'
RUNNING =

Status code indicating that the slave is up and running.

'running'
@@errors =
[]

Class Method Summary collapse

Class Method Details

.check_slave_status(name, configs) ⇒ Object

Checks the value of the MySQL command “SHOW SLAVE STATUS”. Returns a status code.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/reptile/status.rb', line 35

def self.check_slave_status(name, configs)
  # TODO: Do this in Databases
  configs.delete("port")
  Databases.connect(configs.merge(user).merge('database' => 'information_schema')).execute('SHOW SLAVE STATUS').each_hash do |hash|

    if hash['Slave_SQL_Running'] == "No"
      return SQL_THREAD_DOWN
    elsif hash['Slave_IO_Running'] == "No"
      return IO_THREAD_DOWN
    elsif hash['Slave_Running'] == "No"
      return SLAVE_DOWN
    else
      return RUNNING
    end
  end
end

.get_error_message(status) ⇒ Object

Returns a nice error message for the given status code



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/reptile/status.rb', line 53

def self.get_error_message(status)
  case status
  when SQL_THREAD_DOWN
    "The SQL thread has stopped"
  when IO_THREAD_DOWN
    "The IO thread has stopped"
  when SLAVE_DOWN
    "The slave has stoppped"
  else
    raise "Invalid status code.  Must be one of #{status_codes.keys.inspect}"
  end
end

.status_codesObject

A hash containing the names of the constants that represent status codes, and the strings they represent



68
69
70
71
72
73
74
# File 'lib/reptile/status.rb', line 68

def self.status_codes
  status_codes = {}
  self.constants.each do |const|
    status_codes[const] = const_get(const)
  end
  status_codes
end

.userObject

The user settings for a user that has global select privilidgess



29
30
31
# File 'lib/reptile/status.rb', line 29

def self.user
  @user ||= {}
end

.user=(user_settings) ⇒ Object

Set the user settings for a user that has global SELECT privilidgess



24
25
26
# File 'lib/reptile/status.rb', line 24

def self.user=()
  @user = 
end