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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cddd9b64fe9bf5246e9358a2be7c55152becad83
4
- data.tar.gz: 454a56ecdadb14a759ca0e93fb563079a46ab240
3
+ metadata.gz: 33b74209aa5fbce8b7345eed6b427915a1967561
4
+ data.tar.gz: f839052768f3823332b238dae879909e8dcc4418
5
5
  SHA512:
6
- metadata.gz: 4d934cbbc3d5c1c74622b88fd966987ae9d6f5383710b25cc9fa261893abb7625b74760069accba4c37b5778685890e44128c9e86113c9dda57ec552d4f79a6d
7
- data.tar.gz: bd10ab8c46493c296774244040c50f59a33429be339490d033218ceba813bf929af929382214f4fb76a7dc76536e8841ac20f278257cda5c75fea5ff77ad847f
6
+ metadata.gz: b3741d7c4bf1fac02311694a4910d9005f7179a99cbfde003ae69c798ab156a3c2b4a2220e0f188ea508fff357a7e51e3ba75367a043192b5076da6ef3db3191
7
+ data.tar.gz: cdc1ca4cea2825f7ee3f7a10561765943c327fadcf08bc6aa3babe7f26105b3221aa1a14bb3ee36ae1fc8e30a7244197cc67ab7e567bf85d948445651be7c010
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "fluent-plugin-mysql-appender"
4
- spec.version = "0.4.4"
4
+ spec.version = "0.4.5"
5
5
  spec.authors = ["TERASAKI Tsuyoshi"]
6
6
  spec.email = ["tsuyoshi_terasaki@realworld.jp"]
7
7
 
@@ -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
- begin
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
- @threads.each do |thread|
64
- Thread.kill(thread)
65
- end
47
+ Thread.kill(@thread)
66
48
  end
67
49
 
68
- def poll(config)
50
+ private
51
+
52
+ def run
69
53
  begin
70
- tag = format_tag(config)
71
- delay = Config.time_value(config['delay'] || 0)
72
- @mutex.synchronize {
73
- $log.info "mysql_appender_multi: polling start. :tag=>#{tag} :delay=>#{delay}"
74
- }
75
- last_id = get_lastid(config)
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
- db.query(get_query(config, last_id)).each do |row|
81
- if !config['entry_time'].nil? then
82
- entry_time = get_time(row[config['entry_time']])
83
- if (start_time - delay) < entry_time then
84
- break
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
- elapsed_time = sprintf("%0.02f", Time.now - start_time)
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, last_id)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mysql-appender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TERASAKI Tsuyoshi