fluent-plugin-pgjson 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/fluent-plugin-pgjson.gemspec +2 -2
- data/lib/fluent/plugin/out_pgjson.rb +27 -21
- metadata +3 -3
@@ -3,9 +3,9 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-pgjson"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.2"
|
7
7
|
s.authors = ["OKUNO Akihiro"]
|
8
|
-
s.email = ["
|
8
|
+
s.email = ["choplin.choplin@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/choplin/fluent-plugin-pgjson"
|
10
10
|
s.summary = %q{}
|
11
11
|
s.description = %q{}
|
@@ -13,10 +13,10 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
13
13
|
config_param :tag_col , :string , :default => 'tag'
|
14
14
|
config_param :record_col , :string , :default => 'record'
|
15
15
|
|
16
|
-
|
17
16
|
def initialize
|
18
17
|
super
|
19
18
|
require 'pg'
|
19
|
+
@conn = nil
|
20
20
|
end
|
21
21
|
|
22
22
|
def configure(conf)
|
@@ -24,14 +24,10 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
24
24
|
@stmt_name = 'insert'
|
25
25
|
end
|
26
26
|
|
27
|
-
def start
|
28
|
-
super
|
29
|
-
init_connection
|
30
|
-
end
|
31
|
-
|
32
27
|
def shutdown
|
33
28
|
super
|
34
|
-
|
29
|
+
|
30
|
+
if ! @conn.nil? and ! @conn.finished?
|
35
31
|
@conn.close()
|
36
32
|
end
|
37
33
|
end
|
@@ -42,30 +38,40 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
42
38
|
|
43
39
|
def write(chunk)
|
44
40
|
begin
|
41
|
+
init_connection
|
45
42
|
sql = build_sql(chunk)
|
46
43
|
@conn.exec(sql)
|
47
44
|
rescue
|
48
|
-
|
45
|
+
begin
|
46
|
+
@conn.close()
|
47
|
+
rescue
|
48
|
+
end
|
49
|
+
|
50
|
+
@conn = nil
|
49
51
|
raise
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
55
|
private
|
54
56
|
def init_connection
|
55
|
-
|
56
|
-
|
57
|
-
@conn.setnonblocking(true)
|
58
|
-
rescue
|
59
|
-
raise Fluent::ConfigError, "failed to connect PostgreSQL Server at #{@host}:#{@port}"
|
60
|
-
end
|
61
|
-
end
|
57
|
+
if @conn.nil?
|
58
|
+
$log.debug "Connecting to PostgreSQL server #{@host}:#{@port}, database #{@database}..."
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
begin
|
61
|
+
@conn = PGconn.new(:dbname => @database, :host => @host, :port => @port, :user => @user, :password => @password)
|
62
|
+
@conn.setnonblocking(true)
|
63
|
+
rescue
|
64
|
+
if ! conn.nil?
|
65
|
+
begin
|
66
|
+
@conn.close()
|
67
|
+
rescue
|
68
|
+
end
|
69
|
+
|
70
|
+
@conn - nil
|
71
|
+
end
|
72
|
+
|
73
|
+
raise
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pgjson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
description: ''
|
47
47
|
email:
|
48
|
-
-
|
48
|
+
- choplin.choplin@gmail.com
|
49
49
|
executables: []
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|