cranium 0.6.1 → 0.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.
- checksums.yaml +4 -4
- data/cranium.gemspec +1 -1
- data/lib/cranium/database.rb +16 -10
- data/lib/cranium/dsl/database_definition.rb +4 -0
- data/spec/cranium/database_spec.rb +34 -0
- data/spec/cranium/dsl/database_definition_spec.rb +34 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b61de113471ffdd1d3b83dccd8076faee6951352456022b1eda76680cc6d52c4
|
4
|
+
data.tar.gz: 10e4a762604b5d985e8675cde783e3165dc4d94da41fe017c05e6b4a8c514b83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1ea26710cf8585f6c081a0f7c5da88213209685ed73fd8deacacef03e17a4423ba47f1974987e3528fbae50e2ce15db1eca521dbf1e30c73ebf4639cbe53bc
|
7
|
+
data.tar.gz: 3b799dc7963a54cd38b7d46b8313a3a76e6350894f6f6162dcd56387a884e36c601573e94deae2ad4d7e5ac31194e36eb3669437adfec45edf13e7585fb8fedf
|
data/cranium.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'cranium'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.7'
|
4
4
|
spec.authors = ['Emarsys Technologies']
|
5
5
|
spec.email = ['smart-insight-dev@emarsys.com']
|
6
6
|
spec.description = %q{Provides Extract, Transform and Load functionality for loading data from CSV files to a Greenplum database.}
|
data/lib/cranium/database.rb
CHANGED
@@ -13,7 +13,9 @@ module Cranium::Database
|
|
13
13
|
|
14
14
|
def self.[](name)
|
15
15
|
@connections ||= {}
|
16
|
-
@connections[name] ||= setup_connection(@definitions[name].connect_to
|
16
|
+
@connections[name] ||= setup_connection(@definitions[name].connect_to,
|
17
|
+
@definitions[name].retry_count,
|
18
|
+
@definitions[name].retry_delay)
|
17
19
|
end
|
18
20
|
|
19
21
|
|
@@ -28,15 +30,19 @@ module Cranium::Database
|
|
28
30
|
private
|
29
31
|
|
30
32
|
|
31
|
-
def self.setup_connection(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def self.setup_connection(connection_details, retry_count = 0, retry_delay = 0)
|
34
|
+
(retry_count + 1).times do |try_count|
|
35
|
+
connection = if Cranium.configuration.log_queries
|
36
|
+
Sequel.connect(connection_details, loggers: Cranium.configuration.loggers)
|
37
|
+
else
|
38
|
+
Sequel.connect(connection_details)
|
39
|
+
end
|
40
|
+
connection.extension :connection_validator
|
41
|
+
connection.pool.connection_validation_timeout = -1
|
42
|
+
break connection
|
43
|
+
rescue Sequel::DatabaseConnectionError
|
44
|
+
(try_count == retry_count) ? raise : sleep(retry_delay)
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
end
|
@@ -7,11 +7,15 @@ class Cranium::DSL::DatabaseDefinition
|
|
7
7
|
attr_reader :name
|
8
8
|
|
9
9
|
define_attribute :connect_to
|
10
|
+
define_attribute :retry_count
|
11
|
+
define_attribute :retry_delay
|
10
12
|
|
11
13
|
|
12
14
|
|
13
15
|
def initialize(name)
|
14
16
|
@name = name
|
17
|
+
@retry_count = 0
|
18
|
+
@retry_delay = 0
|
15
19
|
end
|
16
20
|
|
17
21
|
|
@@ -81,6 +81,40 @@ describe Cranium::Database do
|
|
81
81
|
|
82
82
|
expect(database[:dwh]).not_to eq database[:dwh2]
|
83
83
|
end
|
84
|
+
|
85
|
+
context 'when retry_count is specified' do
|
86
|
+
before do
|
87
|
+
database.register_database :dwh do
|
88
|
+
connect_to "other connection string"
|
89
|
+
retry_count 3
|
90
|
+
retry_delay 15
|
91
|
+
end
|
92
|
+
allow(database).to receive(:sleep)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should retry connecting to the DB the specified number of times" do
|
96
|
+
call_count = 0
|
97
|
+
allow(Sequel).to receive(:connect) do
|
98
|
+
call_count += 1
|
99
|
+
call_count < 3 ? raise(Sequel::DatabaseConnectionError) : connection
|
100
|
+
end
|
101
|
+
|
102
|
+
expect(database[:dwh]).to eq connection
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not retry connecting to the DB more than the specified number of times" do
|
106
|
+
allow(Sequel).to receive(:connect).exactly(4).times.and_raise(Sequel::DatabaseConnectionError)
|
107
|
+
|
108
|
+
expect { database[:dwh] }.to raise_error(Sequel::DatabaseConnectionError)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should wait retry_delay seconds between connection attempts" do
|
112
|
+
allow(Sequel).to receive(:connect).and_raise(Sequel::DatabaseConnectionError)
|
113
|
+
expect(database).to receive(:sleep).with(15).exactly(3).times
|
114
|
+
|
115
|
+
expect { database[:dwh] }.to raise_error(Sequel::DatabaseConnectionError)
|
116
|
+
end
|
117
|
+
end
|
84
118
|
end
|
85
119
|
|
86
120
|
end
|
@@ -20,4 +20,38 @@ describe Cranium::DSL::DatabaseDefinition do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
|
24
|
+
describe "#retry_count" do
|
25
|
+
context 'when not set' do
|
26
|
+
it "should return 0 by default" do
|
27
|
+
expect(database.retry_count).to eq(0)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when set' do
|
32
|
+
it "should return the number of retries specified for the database" do
|
33
|
+
database.retry_count 3
|
34
|
+
|
35
|
+
expect(database.retry_count).to eq(3)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
describe "#retry_delay" do
|
42
|
+
context 'when not set' do
|
43
|
+
it "should return 0 by default" do
|
44
|
+
expect(database.retry_delay).to eq(0)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when set' do
|
49
|
+
it "should return the number of retries specified for the database" do
|
50
|
+
database.retry_delay 15
|
51
|
+
|
52
|
+
expect(database.retry_delay).to eq(15)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
23
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cranium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emarsys Technologies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -317,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
317
|
- !ruby/object:Gem::Version
|
318
318
|
version: '0'
|
319
319
|
requirements: []
|
320
|
-
rubygems_version: 3.0.
|
320
|
+
rubygems_version: 3.0.1
|
321
321
|
signing_key:
|
322
322
|
specification_version: 4
|
323
323
|
summary: Pure Ruby ETL framework
|