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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf60640829ad3e3977a453a18b4a91c01538ecfe79fb8759b3d978348e10cb8c
4
- data.tar.gz: e297e5c85dd7f0c6296aa1e9ce01dc112d43b08e7087e34f266ff856a0e41ac9
3
+ metadata.gz: b61de113471ffdd1d3b83dccd8076faee6951352456022b1eda76680cc6d52c4
4
+ data.tar.gz: 10e4a762604b5d985e8675cde783e3165dc4d94da41fe017c05e6b4a8c514b83
5
5
  SHA512:
6
- metadata.gz: c47d42ecea886eb75e21b471c9e7b5cdc810d020174e43a76b5554cd3f4f6a71d2517bde5e041a544167ec461d74e2c0945459ac7b3223bf6793ef9fe4d0192d
7
- data.tar.gz: 9dbc134d24bd752b0adfe664d2a0187fb07a8c3e8d0a3d956b5949a7135dbe1c147e158bd6c5f54eca9580f0f424fd56d68b88a032e8352c7709c6ade6c673da
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.6.1'
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.}
@@ -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(connection_string)
32
- connection = if Cranium.configuration.log_queries
33
- Sequel.connect(connection_string, loggers: Cranium.configuration.loggers)
34
- else
35
- Sequel.connect(connection_string)
36
- end
37
- connection.extension :connection_validator
38
- connection.pool.connection_validation_timeout = -1
39
- return connection
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.6.1
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: 2019-12-05 00:00:00.000000000 Z
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.3
320
+ rubygems_version: 3.0.1
321
321
  signing_key:
322
322
  specification_version: 4
323
323
  summary: Pure Ruby ETL framework