pg_failover 1.0.0 → 1.1.0

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: 7165a4aee2751c99cbbcdf92a60e57c0015fce1bb9d714840fa60f24e7755239
4
- data.tar.gz: f60669765090584b6f792200cde5248d29490f02bc4777fb0a84473b52621c71
3
+ metadata.gz: 877a946368b8da5dc3d2c108cdf692d6339b19b576c8e4f6329477aeb197ef07
4
+ data.tar.gz: 9635ed678bdd5677a39dfc259ef93f75bdb44ae79ca7945b07e603676d50f5dc
5
5
  SHA512:
6
- metadata.gz: af8359d882cadde831c9695c24cd3609c47e0afe3b13e092417d8bbde5e8c7530671c43bba56e0efad0218d147132723342b13862499246396e11e179fef8f54
7
- data.tar.gz: c220e6922b14249ba58dd4e4c3e3977143d3c44ef783e6ce08c1f7c857dcb6e05c724d105735d88b49def4f302dd498b73f9d85ee627ebf8dd91703b1ca66744
6
+ metadata.gz: 4310c4d6ea9bec147d95a6b91acf20edc9974f1f645ff70f8e71961c616fbebe71abe23a551d7eaabe9f09830261b853139f23e6d51edf12389463de6e7fa1d1
7
+ data.tar.gz: 76c314590a3b371d10c2644c03834202ee0fac42922ff9bb6002df9d95fc2adc8aab283cd08737944aafe83fbf9649fbc6d5dbd62f1c9739c61b5b7587968f09
@@ -12,6 +12,13 @@ commands:
12
12
  key: pg_failover-{{ checksum "pg_failover.gemspec" }}-{{ checksum "Gemfile" }}
13
13
  paths:
14
14
  - vendor/bundle
15
+
16
+ style:
17
+ steps:
18
+ - run:
19
+ name: Run static code analysis
20
+ command: bundle exec rubocop
21
+
15
22
  test:
16
23
  steps:
17
24
  - run:
@@ -43,6 +50,7 @@ jobs:
43
50
  steps:
44
51
  - checkout
45
52
  - install-dependencies
53
+ - style
46
54
  - test
47
55
  publish:
48
56
  executor:
@@ -62,24 +70,12 @@ jobs:
62
70
  - run:
63
71
  name: Publish gem
64
72
  command: |
65
- package=$(ls -t1 pkg/pg_failover-*.gem | head -1)
73
+ package="$(ls -t1 pkg/pg_failover-*.gem | head -1)"
66
74
  gem push "$package"
67
75
 
68
76
  workflows:
69
77
  test-and-publish:
70
78
  jobs:
71
- - build:
72
- filters:
73
- tags:
74
- only: /.*/
75
- name: "ruby23"
76
- tag: "2.3"
77
- - build:
78
- filters:
79
- tags:
80
- only: /.*/
81
- name: "ruby24"
82
- tag: "2.4"
83
79
  - build:
84
80
  filters:
85
81
  tags:
@@ -92,6 +88,12 @@ workflows:
92
88
  only: /.*/
93
89
  name: "ruby26"
94
90
  tag: "2.6"
91
+ - build:
92
+ filters:
93
+ tags:
94
+ only: /.*/
95
+ name: "ruby27"
96
+ tag: "2.7"
95
97
  - publish:
96
98
  context: org-rubygems
97
99
  filters:
@@ -100,7 +102,6 @@ workflows:
100
102
  tags:
101
103
  only: /^v\d{1,2}\.\d{1,2}\.\d{1,2}.*/
102
104
  requires:
103
- - ruby23
104
- - ruby24
105
105
  - ruby25
106
106
  - ruby26
107
+ - ruby27
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,66 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --exclude-limit 9999999`
3
+ # on 2020-08-21 11:20:01 UTC using RuboCop version 0.89.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'pg_failover.gemspec'
15
+
16
+ # Offense count: 2
17
+ # Configuration parameters: AllowComments.
18
+ Lint/SuppressedException:
19
+ Exclude:
20
+ - 'spec/pg_failover/sequel_adapter_spec.rb'
21
+ - 'spec/pg_failover_spec.rb'
22
+
23
+ # Offense count: 4
24
+ # Cop supports --auto-correct.
25
+ # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
26
+ Lint/UnusedBlockArgument:
27
+ Exclude:
28
+ - 'spec/pg_failover/active_record_adapter_spec.rb'
29
+
30
+ # Offense count: 2
31
+ # Configuration parameters: IgnoredMethods.
32
+ Metrics/AbcSize:
33
+ Max: 22
34
+
35
+ # Offense count: 14
36
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
37
+ # ExcludedMethods: refine
38
+ Metrics/BlockLength:
39
+ Max: 82
40
+
41
+ # Offense count: 3
42
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
43
+ Metrics/MethodLength:
44
+ Max: 18
45
+
46
+ # Offense count: 1
47
+ Metrics/PerceivedComplexity:
48
+ Max: 8
49
+
50
+ # Offense count: 6
51
+ Style/Documentation:
52
+ Exclude:
53
+ - 'spec/**/*'
54
+ - 'test/**/*'
55
+ - 'lib/pg_failover.rb'
56
+ - 'lib/pg_failover/active_record_adapter.rb'
57
+ - 'lib/pg_failover/connection_validator.rb'
58
+ - 'lib/pg_failover/sequel_adapter.rb'
59
+ - 'lib/pg_failover/throttle.rb'
60
+
61
+ # Offense count: 7
62
+ # Cop supports --auto-correct.
63
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
64
+ # URISchemes: http, https
65
+ Layout/LineLength:
66
+ Max: 155
@@ -0,0 +1 @@
1
+ 2.5.8
@@ -1 +1,10 @@
1
+ v1.1.0 Change supported ruby versions
2
+
3
+ Supported:
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
7
+
8
+ No code changes. But from now on the above ruby versions are assumed.
9
+
1
10
  v1.0.0 Initial release.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  group :development, :test do
4
6
  gem 'activerecord'
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # PgFailover
2
+ [![CircleCI](https://circleci.com/gh/FundingCircle/pg_failover/tree/master.svg?style=svg)](https://circleci.com/gh/FundingCircle/pg_failover/tree/master)
3
+ [![Gem Version](https://img.shields.io/gem/v/pg_failover.svg)](https://rubygems.org/gems/pg_failover)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d91a350f5b3e9dd025d3/maintainability)](https://codeclimate.com/github/FundingCircle/pg_failover/maintainability)
2
5
 
3
6
  Handle potential failover events in PostgreSQL database connections by
4
7
  reconnecting if the database is in a recovery mode. This check occurs when a
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "pg_failover"
5
- require "irb"
4
+ require 'bundler/setup'
5
+ require 'pg_failover'
6
+ require 'irb'
6
7
 
7
8
  IRB.start(__FILE__)
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PgFailover
2
4
  autoload :ActiveRecordAdapter, 'pg_failover/active_record_adapter'
3
5
  autoload :Config, 'pg_failover/config'
4
- autoload :ConnectionValidator, 'pg_failover/connection_validator'
6
+ autoload :ConnectionValidator, 'pg_failover/connection_validator'
5
7
  autoload :SequelAdapter, 'pg_failover/sequel_adapter'
6
8
  autoload :Throttle, 'pg_failover/throttle'
7
9
 
@@ -20,12 +20,8 @@ module PgFailover
20
20
  self[:max_retries] ||= (ENV['POSTGRES_FAILOVER_MAX_RETRIES'] || 1).to_i
21
21
  end
22
22
 
23
- def enabled
24
- self[:enabled] ||= %w(1 t true).include?(ENV['POSTGRES_FAILOVER_ENABLED'])
25
- end
26
-
27
23
  def enabled?
28
- !!enabled
24
+ self[:enabled] ||= %w[1 t true].include?(ENV['POSTGRES_FAILOVER_ENABLED'])
29
25
  end
30
26
  end
31
27
  end
@@ -19,13 +19,13 @@ module PgFailover
19
19
  end
20
20
 
21
21
  module ConnectionValidator
22
- def acquire(*a)
22
+ def acquire(*adapter)
23
23
  connection = super
24
24
 
25
25
  PgFailover.connection_validator.call(
26
26
  throttle_by: connection,
27
27
  in_recovery: proc {
28
- result = connection.execute('select pg_is_in_recovery()') { |r| r.to_a }.first
28
+ result = connection.execute('select pg_is_in_recovery()', &:to_a).first
29
29
  %w[1 t true].include?(result['pg_is_in_recovery'].to_s)
30
30
  },
31
31
  reconnect: proc {
@@ -33,9 +33,9 @@ module PgFailover
33
33
  # https://github.com/jeremyevans/sequel/blob/5.15.0/lib/sequel/extensions/connection_validator.rb#L103-L109
34
34
  #
35
35
  if pool_type == :sharded_threaded
36
- sync{allocated(a.last).delete(Thread.current)}
36
+ sync { allocated(adapter.last).delete(Thread.current) }
37
37
  else
38
- sync{@allocated.delete(Thread.current)}
38
+ sync { @allocated.delete(Thread.current) }
39
39
  end
40
40
 
41
41
  disconnect_connection(connection)
@@ -1,35 +1,41 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |spec|
2
- spec.name = "pg_failover"
3
- spec.version = "1.0.0"
4
- spec.authors = ["Aleksandar Ivanov", "Andy Chambers", "Sasha Gerrand"]
5
- spec.email = ["engineering+pg_failover@fundingcircle.com"]
6
- spec.license = "BSD-3-Clause"
4
+ spec.name = 'pg_failover'
5
+ spec.version = '1.1.0'
6
+ spec.authors = ['Aleksandar Ivanov', 'Andy Chambers', 'Sasha Gerrand']
7
+ spec.email = ['engineering+pg_failover@fundingcircle.com']
8
+ spec.license = 'BSD-3-Clause'
7
9
 
8
- spec.summary = %q{Handle Postgres failover events gracefully.}
9
- spec.description = %q{Handle Postgres failover events gracefully using your favourite ORM.}
10
- spec.homepage = "https://github.com/FundingCircle/pg_failover"
10
+ spec.summary = 'Handle Postgres failover events gracefully.'
11
+ spec.description = 'Handle Postgres failover events gracefully using your favourite ORM.'
12
+ spec.homepage = 'https://github.com/FundingCircle/pg_failover'
11
13
 
12
14
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
13
15
  # to allow pushing to a single host or delete this section to allow pushing to any host.
14
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless spec.respond_to?(:metadata)
16
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
15
17
 
16
18
  spec.metadata = {
17
- "changelog_uri" => "https://github.com/FundingCircle/pg_failover/blob/master/CHANGELOG.md",
18
- "homepage_uri" => spec.homepage,
19
- "source_code_uri" => "https://github.com/FundingCircle/pg_failover",
19
+ 'changelog_uri' => 'https://github.com/FundingCircle/pg_failover/blob/master/CHANGELOG.md',
20
+ 'homepage_uri' => spec.homepage,
21
+ 'source_code_uri' => 'https://github.com/FundingCircle/pg_failover'
20
22
  }
21
23
 
22
24
  # Specify which files should be added to the gem when it is released.
23
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
27
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
28
  end
27
- spec.bindir = "exe"
29
+ spec.bindir = 'exe'
28
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
- spec.require_paths = ["lib"]
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.required_ruby_version = '~> 2.5'
30
34
 
31
- spec.add_development_dependency "bundler", "~> 1.17"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "rspec_junit_formatter", "~> 0.4"
35
+ spec.add_development_dependency 'bundler'
36
+ spec.add_development_dependency 'rake', '~> 12.3'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
39
+ spec.add_development_dependency 'rubocop'
40
+ spec.add_development_dependency 'rubocop-rspec'
35
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksandar Ivanov
@@ -10,36 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-02-06 00:00:00.000000000 Z
13
+ date: 2020-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '1.17'
21
+ version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '1.17'
28
+ version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '10.0'
35
+ version: '12.3'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '10.0'
42
+ version: '12.3'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rspec
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +68,34 @@ dependencies:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0.4'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop-rspec
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
71
99
  description: Handle Postgres failover events gracefully using your favourite ORM.
72
100
  email:
73
101
  - engineering+pg_failover@fundingcircle.com
@@ -78,6 +106,9 @@ files:
78
106
  - ".circleci/config.yml"
79
107
  - ".gitignore"
80
108
  - ".rspec"
109
+ - ".rubocop.yml"
110
+ - ".rubocop_todo.yml"
111
+ - ".ruby-version"
81
112
  - CHANGELOG.md
82
113
  - Gemfile
83
114
  - LICENSE
@@ -105,16 +136,16 @@ require_paths:
105
136
  - lib
106
137
  required_ruby_version: !ruby/object:Gem::Requirement
107
138
  requirements:
108
- - - ">="
139
+ - - "~>"
109
140
  - !ruby/object:Gem::Version
110
- version: '0'
141
+ version: '2.5'
111
142
  required_rubygems_version: !ruby/object:Gem::Requirement
112
143
  requirements:
113
144
  - - ">="
114
145
  - !ruby/object:Gem::Version
115
146
  version: '0'
116
147
  requirements: []
117
- rubygems_version: 3.0.1
148
+ rubygems_version: 3.1.2
118
149
  signing_key:
119
150
  specification_version: 4
120
151
  summary: Handle Postgres failover events gracefully.