fluent-plugin-mysql-appender 0.4.4 → 0.4.5
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.
- checksums.yaml +4 -4
- data/fluent-plugin-mysql-appender.gemspec +1 -1
- data/lib/fluent/plugin/in_mysql_appender_multi.rb +34 -49
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33b74209aa5fbce8b7345eed6b427915a1967561
|
4
|
+
data.tar.gz: f839052768f3823332b238dae879909e8dcc4418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3741d7c4bf1fac02311694a4910d9005f7179a99cbfde003ae69c798ab156a3c2b4a2220e0f188ea508fff357a7e51e3ba75367a043192b5076da6ef3db3191
|
7
|
+
data.tar.gz: cdc1ca4cea2825f7ee3f7a10561765943c327fadcf08bc6aa3babe7f26105b3221aa1a14bb3ee36ae1fc8e30a7244197cc67ab7e567bf85d948445651be7c010
|
@@ -37,68 +37,53 @@ module Fluent
|
|
37
37
|
if !File.exist?(@yaml_path)
|
38
38
|
raise Fluent::ConfigError, "mysql_appender_multi: No such file in 'yaml_path'."
|
39
39
|
end
|
40
|
-
|
41
|
-
if @tag.nil?
|
42
|
-
raise Fluent::ConfigError, "mysql_appender_multi: missing 'tag' parameter. Please add following line into config like 'tag appender.${name}.${event}.${primary_key}'"
|
43
|
-
end
|
44
40
|
end
|
45
41
|
|
46
42
|
def start
|
47
|
-
|
48
|
-
@threads = []
|
49
|
-
@mutex = Mutex.new
|
50
|
-
YAML.load_file(@yaml_path).each do |config|
|
51
|
-
@threads << Thread.new {
|
52
|
-
poll(config)
|
53
|
-
}
|
54
|
-
end
|
55
|
-
$log.error "mysql_appender_multi: stop working due to empty configuration" if @threads.empty?
|
56
|
-
rescue => e
|
57
|
-
$log.error "error: #{e.message}"
|
58
|
-
$log.error e.backtrace.join("\n")
|
59
|
-
end
|
43
|
+
@thread = Thread.new(&method(:run))
|
60
44
|
end
|
61
45
|
|
62
46
|
def shutdown
|
63
|
-
@
|
64
|
-
Thread.kill(thread)
|
65
|
-
end
|
47
|
+
Thread.kill(@thread)
|
66
48
|
end
|
67
49
|
|
68
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
def run
|
69
53
|
begin
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
54
|
+
# initialize
|
55
|
+
configs = YAML.load_file(@yaml_path)
|
56
|
+
configs.each do |config|
|
57
|
+
config['last_id'] = get_lastid(config)
|
58
|
+
config['tag'] = format_tag(config)
|
59
|
+
config['delay'] = Config.time_value(config['delay'] || 0)
|
60
|
+
end
|
61
|
+
|
76
62
|
loop do
|
77
|
-
rows_count = 0
|
78
|
-
start_time = Time.now
|
79
63
|
db = get_connection
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if
|
84
|
-
|
64
|
+
configs.each do |config|
|
65
|
+
db.query(get_query(config)).each do |row|
|
66
|
+
rows_count = 0
|
67
|
+
if !config['entry_time'].nil? then
|
68
|
+
entry_time = get_time(row[config['entry_time']])
|
69
|
+
if (start_time - config['delay']) < entry_time then
|
70
|
+
break
|
71
|
+
end
|
85
72
|
end
|
73
|
+
if config['time_column'].nil? then
|
74
|
+
td_time = Engine.now
|
75
|
+
else
|
76
|
+
td_time = get_time(row[config['time_column']]).to_i
|
77
|
+
end
|
78
|
+
row.each {|k, v| row[k] = v.to_s if v.is_a?(Time) || v.is_a?(Date) || v.is_a?(BigDecimal)}
|
79
|
+
router.emit(config['tag'], td_time, row)
|
80
|
+
rows_count += 1
|
81
|
+
config['last_id'] = row[config['primary_key']]
|
82
|
+
$log.info "mysql_appender_multi: :tag=>#{config['tag']} :rows_count=>#{rows_count} :last_id=>#{config['last_id']} "
|
86
83
|
end
|
87
|
-
if config['time_column'].nil? then
|
88
|
-
td_time = Engine.now
|
89
|
-
else
|
90
|
-
td_time = get_time(row[config['time_column']]).to_i
|
91
|
-
end
|
92
|
-
row.each {|k, v| row[k] = v.to_s if v.is_a?(Time) || v.is_a?(Date) || v.is_a?(BigDecimal)}
|
93
|
-
router.emit(tag, td_time, row)
|
94
|
-
rows_count += 1
|
95
|
-
last_id = row[config['primary_key']]
|
96
84
|
end
|
97
85
|
db.close
|
98
|
-
|
99
|
-
@mutex.synchronize {
|
100
|
-
$log.info "mysql_appender_multi: finished execution :tag=>#{tag} :rows_count=>#{rows_count} :last_id=>#{last_id} :elapsed_time=>#{elapsed_time} sec"
|
101
|
-
}
|
86
|
+
$log.info "mysql_appender_multi: finished execution :elapsed_time=>#{elapsed_time} sec"
|
102
87
|
sleep @interval
|
103
88
|
end
|
104
89
|
rescue => e
|
@@ -146,8 +131,8 @@ module Fluent
|
|
146
131
|
end
|
147
132
|
end
|
148
133
|
|
149
|
-
def get_query(config
|
150
|
-
"SELECT #{config['columns'].join(",")} FROM #{config['table_name']} where #{config['primary_key']} > #{last_id} order by #{config['primary_key']} asc limit #{config['limit']}"
|
134
|
+
def get_query(config)
|
135
|
+
"SELECT #{config['columns'].join(",")} FROM #{config['table_name']} where #{config['primary_key']} > #{config['last_id']} order by #{config['primary_key']} asc limit #{config['limit']}"
|
151
136
|
end
|
152
137
|
|
153
138
|
def format_tag(config)
|