activerecord-retriable 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a4f80e0d64c6bb89e4a54db2e3526a89292a2c69db1d4a8ad4559da6879c094a
4
+ data.tar.gz: f397d1d22cea604138a6bc3dd2cb4b98cb2d586673925aa52b05a43379752813
5
+ SHA512:
6
+ metadata.gz: 6e790f21ccb4228b83827f9878d8f4ed83687266c53af7227b82cfe533a7951be1ea7632719eeb8ca4bbf390f6c487c6b9329ef4f02a182db886bf67fc28f0ae
7
+ data.tar.gz: 229aa45458417b5aa4228147973b58e2ac00be4c96c6b11e6a00dc2d9608b18e2646f56f5542795f10a5456f83fad830a436b2d89dfbf3a6acc7681d156b9961
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /log/
7
+ /pkg/
8
+ /spec/db.sqlite3
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ Gemfile.lock
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
16
+ spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'activerecord-5' do
2
+ gem 'activerecord', '~> 5.0'
3
+ end
4
+
5
+ appraise 'activerecord-6' do
6
+ gem 'activerecord', '~> 6.0'
7
+ end
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at joao@hopin.to. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in activerecord-retriable.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 João Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # ActiveRecord::Retriable
2
+
3
+ Retry your `ActiveRecord` transactions. Inspired by
4
+ [Sequel's](http://sequel.jeremyevans.net/) way of doing it.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'activerecord-retriable'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install activerecord-retriable
21
+
22
+ ## Usage
23
+
24
+ Retry if `ActiveRecord::TransactionRollbackError` is raised:
25
+
26
+ ```ruby
27
+ ActiveRecord::Base.transaction(retry_on: ActiveRecord::TransactionRollbackError) do
28
+ ...
29
+ end
30
+ ```
31
+
32
+ Retry if `ActiveRecord::TransactionRollbackError` or
33
+ `ActiveRecord::LockWaitTimeout` are raised:
34
+
35
+ ```ruby
36
+ ActiveRecord::Base.transaction(retry_on: [ActiveRecord::TransactionRollbackError, ActiveRecord::LockWaitTimeout]) do
37
+ ...
38
+ end
39
+ ```
40
+
41
+ By default we retry once. You can change the default number of retries by
42
+ changing:
43
+
44
+ ```ruby
45
+ Rails.configuration.active_record.default_transaction_retries
46
+ ```
47
+
48
+ Or you can override the default value locally:
49
+
50
+ ```ruby
51
+ ActiveRecord::Base.transaction(retry_on: ActiveRecord::TransactionRollbackError
52
+ num_retries: 3) do
53
+ ...
54
+ end
55
+ ```
56
+
57
+ To retry indefinitely, set `num_retries:` to `nil`. Be careful when doing that!
58
+
59
+ To perform an action before retrying, pass an object that responds to `#call` in
60
+ `before_retry:`:
61
+
62
+ ```ruby
63
+ before_retry = ->(num_retries, exception) do
64
+ puts "retrying transaction for the #{num_retries.ordinalize} time: #{exception}"
65
+ end
66
+
67
+ ActiveRecord::Base.transaction(retry_on: ActiveRecord::TransactionRollbackError
68
+ before_retry: before_retry) do
69
+ ...
70
+ end
71
+ ```
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
76
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
77
+ prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`. To
80
+ release a new version, update the version number in `version.rb`, and then run
81
+ `bundle exec rake release`, which will create a git tag for the version, push
82
+ git commits and tags, and push the `.gem` file to
83
+ [rubygems.org](https://rubygems.org).
84
+
85
+ ## Contributing
86
+
87
+ Bug reports and pull requests are welcome on GitHub at
88
+ https://github.com/jcmfernandes/activerecord-retriable. This project is intended
89
+ to be a safe, welcoming space for collaboration, and contributors are expected
90
+ to adhere to the [code of
91
+ conduct](https://github.com/jcmfernandes/activerecord-retriable/blob/master/CODE_OF_CONDUCT.md).
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT
96
+ License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the `ActiveRecord::Retriable` project's codebases, issue
101
+ trackers, chat rooms and mailing lists is expected to follow the [code of
102
+ conduct](https://github.com/jcmfernandes/activerecord-retriable/blob/master/CODE_OF_CONDUCT.md).
103
+
104
+ ## Maintainer
105
+
106
+ João Fernandes <joao.fernandes@ist.utl.pt>
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/activerecord/retriable/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "activerecord-retriable"
5
+ spec.version = ActiveRecord::Retriable::VERSION
6
+ spec.authors = ["João Fernandes"]
7
+ spec.email = ["joao.fernandes@ist.utl.pt"]
8
+
9
+ spec.summary = "Retry your Active Record transactions."
10
+ spec.homepage = "https://github.com/jcmfernandes/activerecord-retriable"
11
+ spec.license = "MIT"
12
+
13
+ # Specify which files should be added to the gem when it is released.
14
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'railties', '>= 5', '< 7'
21
+ spec.add_dependency 'activerecord', '>= 5', '< 7'
22
+ spec.add_dependency 'activesupport', '>= 5', '< 7'
23
+
24
+ spec.add_development_dependency 'appraisal'
25
+ spec.add_development_dependency 'pry-byebug'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'sqlite3'
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activerecord/retriable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 5.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 12.0"
6
+ gem "rspec", "~> 3.0"
7
+ gem "activerecord", "~> 6.0"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/array/wrap'
6
+ require 'active_record'
7
+ require 'active_record/base'
8
+
9
+ module Retriable
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ Rails.configuration.active_record.default_transaction_retries = 1
14
+ end
15
+
16
+ module ClassMethods
17
+ def transaction(retry_on: nil,
18
+ num_retries: Rails.configuration.active_record.default_transaction_retries,
19
+ before_retry: nil,
20
+ **options, &block)
21
+ return super(options, &block) if retry_on.blank?
22
+
23
+ retry_on = Array.wrap(retry_on)
24
+ total_retries = num_retries
25
+ num_retries = 0
26
+ begin
27
+ super(options, &block)
28
+ rescue *retry_on => e
29
+ num_retries += 1
30
+ if total_retries.nil? || num_retries <= total_retries
31
+ before_retry&.call(num_retries, e)
32
+ retry
33
+ end
34
+ raise
35
+ end
36
+ end
37
+ end
38
+ end
39
+ ActiveRecord::Base.include(Retriable)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module Retriable
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-retriable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - João Fernandes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '7'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '5'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: activesupport
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '5'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '7'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '5'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '7'
73
+ - !ruby/object:Gem::Dependency
74
+ name: appraisal
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: pry-byebug
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ name: sqlite3
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ description:
144
+ email:
145
+ - joao.fernandes@ist.utl.pt
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".gitignore"
151
+ - ".rspec"
152
+ - Appraisals
153
+ - CODE_OF_CONDUCT.md
154
+ - Gemfile
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - activerecord-retriable.gemspec
159
+ - bin/console
160
+ - bin/setup
161
+ - gemfiles/activerecord_5.gemfile
162
+ - gemfiles/activerecord_6.gemfile
163
+ - lib/activerecord/retriable.rb
164
+ - lib/activerecord/retriable/version.rb
165
+ homepage: https://github.com/jcmfernandes/activerecord-retriable
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.1.2
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Retry your Active Record transactions.
188
+ test_files: []