sequel-replica-failover 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dba94be5402e5660e5ae3308c9e8e4463195b34
4
- data.tar.gz: ac4906af1bde935311bb7c492a24f583f9070092
3
+ metadata.gz: 31cc90d47b9bbe08b846ea3af88bb29a647fe6d3
4
+ data.tar.gz: 21ccb990de1601f8f49c4523343a92587abdfc62
5
5
  SHA512:
6
- metadata.gz: b6d2891b1a22ebbff6f74ced00643ed77648ad9c346f87414ba3e5663e23399a62200338380372f3c605e8120be933e818d7768a074d036b64503fe5a3ecf2bf
7
- data.tar.gz: 8782591c54e37e2b1068886bd801b3e8883df2a3d872cfee35aafca4ef5d2e8d81ea12e344dab3f4a4f53c7a1cb6c6af69cc0e9d1e4c6d31c571ce78a0d9841f
6
+ metadata.gz: 0bf16b9998f95ac996b20731c872b481c11482d8d00f145d0a19eed7ad5341f8e01e15417615d210a2b73d6f98ff106f57a3e3f34e33550555c837dd95b0a88b
7
+ data.tar.gz: ddcb1cbb66e57295b5530f8e6a3378152b1b9aaaadf0ad8da7f47169bb39988a62f8f5e9f8956454f485487b391e8442be7ebcbd625db264eb79cd75d88ad8e2
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0-p247
5
+ script: "bundle exec rspec"
6
+ notifications:
7
+ email: false
data/Gemfile CHANGED
@@ -3,5 +3,3 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in sequel-replica-failover.gemspec
4
4
  gemspec
5
5
 
6
- # for testing purposes until pull request is accepted
7
- gem 'ruby-usdt', github: 'sax/ruby-usdt', ref: 'probe-introspection', submodules: true
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Automatic read-only failover for Sequel
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/sequel-replica-failover.png)](http://badge.fury.io/rb/sequel-replica-failover)
4
+ [![Code Climate](https://codeclimate.com/github/wanelo/sequel-replica-failover.png)](https://codeclimate.com/github/wanelo/sequel-replica-failover)
5
+
3
6
  This provides a NOT-THREADSAFE sharded connection pool for failing over between configured replicas.
4
7
 
5
8
  The mechanisms it provides are as follows:
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module ReplicaFailover
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -8,6 +8,10 @@ class Sequel::ShardedSingleFailoverConnectionPool < Sequel::ShardedSingleConnect
8
8
  @pool_retry_count = opts[:pool_retry_count] || 5
9
9
  end
10
10
 
11
+ class << self
12
+ attr_accessor :on_disconnect
13
+ end
14
+
11
15
  # Yields the connection to the supplied block for the given server.
12
16
  # This method simulates the ConnectionPool#hold API.
13
17
  def hold(server=:default, &block)
@@ -18,14 +22,16 @@ class Sequel::ShardedSingleFailoverConnectionPool < Sequel::ShardedSingleConnect
18
22
  end
19
23
 
20
24
  super(server, &block)
21
- rescue Sequel::DatabaseDisconnectError, Sequel::DatabaseConnectionError
25
+ rescue Sequel::DatabaseDisconnectError, Sequel::DatabaseConnectionError => e
22
26
  if server == :read_only && !@db.in_transaction?(server: :read_only)
27
+ self.class.on_disconnect.call(e, self) if self.class.on_disconnect
23
28
  disconnect_server(server)
24
29
  @conns[server] = nil
25
30
 
26
31
  stick
27
32
 
28
33
  if @stuck_times >= @pool_retry_count
34
+ unstick(server)
29
35
  raise
30
36
  end
31
37
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["paul@wanelo.com"]
11
11
  spec.description = %q{Automatically failover between replicas when they go down.}
12
12
  spec.summary = %q{Automatically failover when replicas go down.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/wanelo/sequel-replica-failover"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "sequel", ">= 4.3.0"
22
- spec.add_dependency "ruby-usdt"
22
+ spec.add_dependency "ruby-usdt", ">= 0.2.2"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
@@ -49,6 +49,17 @@ describe Sequel::ShardedSingleFailoverConnectionPool do
49
49
  @connection_pool.hold(:read_only) {}
50
50
  end
51
51
 
52
+ context 'with an on_disconnect callback' do
53
+ it 'calls the callback with the error' do
54
+ callback = double("callback")
55
+ Sequel::ShardedSingleFailoverConnectionPool.on_disconnect = callback
56
+
57
+ expect(callback).to receive(:call).with(an_instance_of(Sequel::DatabaseDisconnectError), @connection_pool)
58
+ call_count = 0
59
+ @connection_pool.hold(:read_only) { call_count += 1; raise Sequel::DatabaseDisconnectError if call_count == 1 }
60
+ end
61
+ end
62
+
52
63
  context 'when in a transaction' do
53
64
  it 'raises an exception' do
54
65
  Sequel::Mock::Database.any_instance.should_receive(:in_transaction?).and_return(true)
@@ -66,4 +77,12 @@ describe Sequel::ShardedSingleFailoverConnectionPool do
66
77
  end
67
78
  end
68
79
  end
80
+
81
+ describe '.on_disconnect' do
82
+ it 'sets the on_disconnect attribute' do
83
+ callback = Proc.new{ puts "woo" }
84
+ Sequel::ShardedSingleFailoverConnectionPool.on_disconnect = callback
85
+ expect(Sequel::ShardedSingleFailoverConnectionPool.on_disconnect).to eq(callback)
86
+ end
87
+ end
69
88
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-replica-failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Henry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-usdt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.2.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: timecop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Automatically failover between replicas when they go down.
@@ -115,8 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - .gitignore
119
- - .rspec
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
120
121
  - Gemfile
121
122
  - Guardfile
122
123
  - LICENSE.txt
@@ -130,7 +131,7 @@ files:
130
131
  - spec/sequel-replica-failover/dtrace_provider_spec.rb
131
132
  - spec/sequel/connection_pool/sharded_single_failover_spec.rb
132
133
  - spec/spec_helper.rb
133
- homepage: ''
134
+ homepage: https://github.com/wanelo/sequel-replica-failover
134
135
  licenses:
135
136
  - MIT
136
137
  metadata: {}
@@ -140,17 +141,17 @@ require_paths:
140
141
  - lib
141
142
  required_ruby_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
- - - '>='
144
+ - - ">="
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  requirements:
148
- - - '>='
149
+ - - ">="
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  requirements: []
152
153
  rubyforge_project:
153
- rubygems_version: 2.0.7
154
+ rubygems_version: 2.2.0
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: Automatically failover when replicas go down.
@@ -158,3 +159,4 @@ test_files:
158
159
  - spec/sequel-replica-failover/dtrace_provider_spec.rb
159
160
  - spec/sequel/connection_pool/sharded_single_failover_spec.rb
160
161
  - spec/spec_helper.rb
162
+ has_rdoc: