murakumo 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.2.8'
2
+ VERSION = '0.2.9'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -39,34 +39,53 @@ module Murakumo
39
39
 
40
40
  begin
41
41
  require 'mysql'
42
- mysql_class = Mysql
43
- rescue LoadError
44
- begin
45
- require 'mysql2'
46
- mysql_class = Mysql2::Client
47
- rescue LoadError
42
+
43
+ def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
44
+ port = nil
45
+ sock = nil
46
+
47
+ if port_sock.kind_of?(Integer)
48
+ port = port_sock
49
+ else
50
+ sock = port_sock
51
+ end
52
+
53
+ my = Mysql.new(host, user, passwd, db, port, sock)
54
+ !!(my.respond_to?(:ping) ? my.ping : my.stat)
55
+ rescue => e
56
+ @logger.debug(e.message)
57
+ return false
58
+ ensure
59
+ my.close if my
48
60
  end
61
+ rescue LoadError
49
62
  end
50
63
 
51
- if mysql_class
52
- class_eval <<-EOS
53
- def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
54
- port = nil
55
- sock = nil
56
-
57
- if port_sock.kind_of?(Integer)
58
- port = port_sock
59
- else
60
- sock = port_sock
61
- end
62
-
63
- my = #{mysql_class}.new(host, user, passwd, db, port, sock)
64
- !!(my.respond_to?(:ping) ? my.ping : my.stat)
65
- rescue => e
66
- @logger.debug(e.message)
67
- false
64
+ begin
65
+ require 'mysql2'
66
+
67
+ def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
68
+ opts = {}
69
+ opts[:username] = user
70
+ opts[:password] = passwd if passwd
71
+ opts[:host] = host if host
72
+ opts[:database] = db if db
73
+
74
+ if port_sock.kind_of?(Integer)
75
+ opts[:port] = port_sock
76
+ else
77
+ opts[:socket] = port_sock
68
78
  end
69
- EOS
79
+
80
+ my = Mysql2::Client.new(opts)
81
+ my.ping
82
+ rescue => e
83
+ @logger.debug(e.message)
84
+ return false
85
+ ensure
86
+ my.close if my
87
+ end
88
+ rescue LoadError
70
89
  end
71
90
 
72
91
  end # HealthCheckerContext
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murakumo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel