murakumo 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -12,6 +12,7 @@ module Murakumo
12
12
  @name = name
13
13
  @cloud = cloud
14
14
  @logger = logger
15
+ @options = options
15
16
 
16
17
  # 各種変数の設定
17
18
  {
@@ -97,7 +98,7 @@ module Murakumo
97
98
 
98
99
  begin
99
100
  retval = timeout(@timeout) {
100
- HealthCheckerContext.new.instance_eval(@script)
101
+ HealthCheckerContext.new(:name => @name, :logger => @logger, :options => @options).instance_eval(@script)
101
102
  }
102
103
  rescue Timeout::Error
103
104
  retval = false
@@ -8,6 +8,12 @@ module Murakumo
8
8
  # ヘルスチェックのコンテキスト
9
9
  class HealthCheckerContext
10
10
 
11
+ def initialize(vars = {})
12
+ vars.each do |name, val|
13
+ instance_variable_set("@#{name}", val)
14
+ end
15
+ end
16
+
11
17
  # TCPチェッカー
12
18
  def tcp_check(port, host = '127.0.0.1')
13
19
  s = TCPSocket.new(host, port)
@@ -29,35 +35,38 @@ module Murakumo
29
35
  end
30
36
 
31
37
  # MySQLのドライバがあれば、MySQLチェッカーを定義
32
- has_mysql = false
38
+ mysql_class = nil
33
39
 
34
40
  begin
35
41
  require 'mysql'
36
- has_mysql = true
42
+ mysql_class = Mysql
37
43
  rescue LoadError
38
44
  begin
39
45
  require 'mysql2'
40
- has_mysql = true
46
+ mysql_class = Mysql2
41
47
  rescue LoadError
42
48
  end
43
49
  end
44
50
 
45
- if has_mysql
46
- def mysql_check(user, passwd = nil, port_sock = 3306, host = '127.0.0.1', db = nil)
47
- port = nil
48
- sock = nil
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
49
56
 
50
- if port_sock.kind_of?(Integer)
51
- port = port_sock
52
- else
53
- sock = port_sock
54
- end
57
+ if port_sock.kind_of?(Integer)
58
+ port = port_sock
59
+ else
60
+ sock = port_sock
61
+ end
55
62
 
56
- my = Mysql.new(host, user, passwd, db, port, sock)
57
- !!(my.respond_to?(:ping) ? my.ping : my.stat)
58
- rescue
59
- false
60
- end
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
68
+ end
69
+ EOS
61
70
  end
62
71
 
63
72
  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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel