sidekiq-transaction_guard 1.0.1 → 1.0.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
  SHA256:
3
- metadata.gz: e27eee15051c5f07cf60ef45c168acc319c41883a7b67f398b7699555d7eebad
4
- data.tar.gz: 4c7468a9c73455fe68eec99c6b0e756f510a8d8d2f83983523a9cb3871ead584
3
+ metadata.gz: 0fe8af50053f7431c866b6091475ac6c11498619b6dc443e3a6320fa54ce41e0
4
+ data.tar.gz: fc14706b5ad35440b365db3065f12f5342ecf048a2a29e96a0baecff8179ea0a
5
5
  SHA512:
6
- metadata.gz: 23aae8c43a758882aa38de9c7cce90c709ecca1784e7c56c78e223db406d7bec88fba99fa5794226fe8a94d6a23f764b11b2e3ed42f6017847bddefa42350ecc
7
- data.tar.gz: 668a578d96d136cd382a400efbf46f6f94715c53917e017c6833a5f5cf362e24254f1fa2444350a09509201785b9d62adef9008d238bbe0c40aec9ed144bb1c7
6
+ metadata.gz: e4902e75a12e5b2ae4943cd415cbe7e4173db2304b8c431d40e49cd51b4c41a8acb5f23e0c20f8f1d2062593f559b4edb34ea479621988cc6df55f4e0a749a4f
7
+ data.tar.gz: 88cbea82b257c33439955f45e49a36beba1d0b7b72de2a7f4fb74d6bfbda6cfc2c292bbfc12b6eed8d0ac0cf9f6565f46d9508aa100be29d6fc8f954230c389f
@@ -0,0 +1,12 @@
1
+ # Dependabot update strategy
2
+ version: 2
3
+ updates:
4
+ - package-ecosystem: bundler
5
+ directory: "/"
6
+ schedule:
7
+ interval: weekly
8
+ allow:
9
+ # Automatically keep all runtime dependencies updated
10
+ - dependency-name: "*"
11
+ dependency-type: "production"
12
+ versioning-strategy: lockfile-only
@@ -0,0 +1,84 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ - actions-*
8
+ tags:
9
+ - v*
10
+ pull_request:
11
+ branches-ignore:
12
+ - actions-*
13
+
14
+ env:
15
+ BUNDLE_CLEAN: "true"
16
+ BUNDLE_PATH: vendor/bundle
17
+ BUNDLE_JOBS: 3
18
+ BUNDLE_RETRY: 3
19
+
20
+ jobs:
21
+ build:
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ include:
27
+ - ruby: "ruby"
28
+ standardrb: true
29
+ - ruby: "3.2"
30
+ appraisal: "activerecord_7.0"
31
+ - ruby: "3.1"
32
+ appraisal: "activerecord_6.1"
33
+ - ruby: "2.7"
34
+ appraisal: "activerecord_6.0"
35
+ - ruby: "2.7"
36
+ appraisal: "activerecord_5.2"
37
+ - ruby: "2.6"
38
+ appraisal: "activerecord_5.1"
39
+ - ruby: "2.6"
40
+ appraisal: "activerecord_5.0"
41
+ - ruby: "2.5"
42
+ appraisal: "activerecord_4.2"
43
+ - ruby: "2.5"
44
+ appraisal: "activerecord_4.1"
45
+ - ruby: "2.5"
46
+ appraisal: "activerecord_4.0"
47
+ - ruby: "3.2"
48
+ appraisal: "sidekiq_7"
49
+ - ruby: "3.0"
50
+ appraisal: "sidekiq_6"
51
+ - ruby: "2.7"
52
+ appraisal: "sidekiq_5"
53
+ - ruby: "2.6"
54
+ appraisal: "sidekiq_4"
55
+ - ruby: "2.5"
56
+ appraisal: "sidekiq_3"
57
+ steps:
58
+ - uses: actions/checkout@v2
59
+ - name: Set up Ruby ${{ matrix.ruby }}
60
+ uses: ruby/setup-ruby@v1
61
+ with:
62
+ ruby-version: "${{ matrix.ruby }}"
63
+ - name: Install packages
64
+ run: |
65
+ sudo apt-get update
66
+ sudo apt-get install libsqlite3-dev
67
+ - name: Setup bundler
68
+ if: matrix.bundler != ''
69
+ run: |
70
+ gem uninstall bundler --all
71
+ gem install bundler --no-document --version ${{ matrix.bundler }}
72
+ - name: Set Appraisal bundle
73
+ if: matrix.appraisal != ''
74
+ run: |
75
+ echo "using gemfile gemfiles/${{ matrix.appraisal }}.gemfile"
76
+ bundle config set gemfile "gemfiles/${{ matrix.appraisal }}.gemfile"
77
+ - name: Install gems
78
+ run: |
79
+ bundle update
80
+ - name: Run Tests
81
+ run: bundle exec rake
82
+ - name: standardrb
83
+ if: matrix.standardrb == true
84
+ run: bundle exec rake standard
data/.standard.yml ADDED
@@ -0,0 +1,9 @@
1
+ format: progress
2
+
3
+ ruby_version: 2.5
4
+
5
+ ignore:
6
+ - 'spec/**/*':
7
+ - Lint/ConstantDefinitionInBlock
8
+ - Lint/UselessAssignment
9
+
data/CHANGELOG.md CHANGED
@@ -1,7 +1,21 @@
1
- # 1.0.1
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
2
3
 
3
- * Sidekiq 6.0 compatibility
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
6
 
5
- # 1.0.0
7
+ ## 1.0.2
6
8
 
7
- * Initial release
9
+ ### Changed
10
+ - Updated database cleaner dependency to use database_cleaner-active_record instead of deprecated database_cleaner gem.
11
+ - Added YARD doc param and return types.
12
+
13
+ ## 1.0.1
14
+
15
+ ### Added
16
+ - Sidekiq 6.0 compatibility
17
+
18
+ ## 1.0.0
19
+
20
+ ### Added
21
+ - Initial release
data/README.md CHANGED
@@ -59,7 +59,7 @@ end
59
59
  You can use this gem to add Sidekiq client middleware that will either warn you or raise an error when workers are scheduled inside of a database transaction. You can do this by simply adding this to your application's initialization code:
60
60
 
61
61
  ```ruby
62
- require 'sidekiq/transaction-guard'
62
+ require 'sidekiq/transaction_guard'
63
63
 
64
64
  Sidekiq.configure_client do |config|
65
65
  config.client_middleware do |chain|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -1,6 +1,7 @@
1
- require 'sidekiq/transaction_guard'
2
- require 'database_cleaner'
3
- require 'database_cleaner/active_record/transaction'
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq/transaction_guard"
4
+ require "database_cleaner/active_record"
4
5
 
5
6
  module Sidekiq
6
7
  module TransactionGuard
@@ -16,8 +17,10 @@ module Sidekiq
16
17
 
17
18
  # Wrap the `Sidekiq::TransactionGuard.testing` which sets up the data structures
18
19
  # needed for custom counting of the transaction level within a test block.
20
+ #
21
+ # @return [Object] the return value of the block
19
22
  def cleaning(&block)
20
- Sidekiq::TransactionGuard.testing{ super(&block) }
23
+ Sidekiq::TransactionGuard.testing { super(&block) }
21
24
  end
22
25
  end
23
26
  end
@@ -21,16 +21,16 @@ module Sidekiq
21
21
 
22
22
  private
23
23
 
24
- def worker_mode(worker_class)
25
- read_sidekiq_option(worker_class, :transaction_guard) || Sidekiq::TransactionGuard.mode
24
+ def worker_mode(job)
25
+ read_sidekiq_option(job, :transaction_guard) || Sidekiq::TransactionGuard.mode
26
26
  end
27
27
 
28
28
  def in_transaction?
29
29
  Sidekiq::TransactionGuard.in_transaction?
30
30
  end
31
31
 
32
- def notify_block(worker_class)
33
- handler = read_sidekiq_option(worker_class, :notify_in_transaction)
32
+ def notify_block(job)
33
+ handler = read_sidekiq_option(job, :notify_in_transaction)
34
34
  if handler
35
35
  handler
36
36
  elsif handler == false
@@ -40,13 +40,13 @@ module Sidekiq
40
40
  end
41
41
  end
42
42
 
43
- def read_sidekiq_option(worker_class, option_name)
44
- options = worker_class.sidekiq_options_hash
45
- options[option_name.to_s] if options
43
+ def read_sidekiq_option(job, option_name)
44
+ # options = worker_class.sidekiq_options_hash
45
+ job[option_name.to_s]
46
46
  end
47
47
 
48
48
  def notify!(worker_class, job)
49
- notify_handler = notify_block(worker_class)
49
+ notify_handler = notify_block(job)
50
50
  if notify_handler
51
51
  begin
52
52
  notify_handler.call(job)
@@ -54,14 +54,14 @@ module Sidekiq
54
54
  if Sidekiq.logger
55
55
  Sidekiq.logger.error(e)
56
56
  else
57
- STDERR.write("ERROR on Sidekiq::TransactionGuard notify block for #{worker_class}: #{e.inspect}\n")
57
+ $stderr.write("ERROR on Sidekiq::TransactionGuard notify block for #{worker_class}: #{e.inspect}\n")
58
58
  end
59
59
  end
60
60
  end
61
61
  end
62
62
 
63
63
  def log_transaction(worker_class, job)
64
- mode = worker_mode(worker_class)
64
+ mode = worker_mode(job)
65
65
  if mode != :disabled
66
66
  message = "#{worker_class.name} was called from inside a database transaction"
67
67
  if mode == :error
@@ -71,7 +71,7 @@ module Sidekiq
71
71
  if logger
72
72
  logger.warn(message)
73
73
  else
74
- STDERR.write("WARNING #{message}\n")
74
+ $stderr.write("WARNING #{message}\n")
75
75
  end
76
76
  notify!(worker_class, job)
77
77
  end
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sidekiq'
4
- require 'set'
5
- require 'thread'
3
+ require "sidekiq"
4
+ require "set"
6
5
 
7
- require_relative 'transaction_guard/middleware'
6
+ require_relative "transaction_guard/middleware"
8
7
 
9
8
  module Sidekiq
10
9
  module TransactionGuard
@@ -26,6 +25,9 @@ module Sidekiq
26
25
  # * :stderr - Log to STDERR
27
26
  # * :error - Throw a `Sidekiq::TransactionGuard::InsideTransactionError`
28
27
  # * :disabled - Allow workers inside of transactions
28
+ #
29
+ # @param mode [Symbol]
30
+ # @return [void]
29
31
  def mode=(symbol)
30
32
  if VALID_MODES.include?(symbol)
31
33
  @mode = symbol
@@ -35,18 +37,22 @@ module Sidekiq
35
37
  end
36
38
 
37
39
  # Return the current mode.
38
- def mode
39
- @mode
40
- end
40
+ #
41
+ # @return [Symbol]
42
+ attr_reader :mode
41
43
 
42
44
  # Define the global notify block. This block will be called with a Sidekiq
43
45
  # job hash for all jobs enqueued inside transactions if the mode is `:warn`
44
46
  # or `:stderr`.
47
+ #
48
+ # @return [void]
45
49
  def notify(&block)
46
50
  @notify = block
47
51
  end
48
52
 
49
53
  # Return the block set as the notify handler with a call to `notify`.
54
+ #
55
+ # @return [Proc]
50
56
  def notify_block
51
57
  @notify
52
58
  end
@@ -55,15 +61,20 @@ module Sidekiq
55
61
  # being monitored for open transactions. You don't need to add `ActiveRecord::Base`
56
62
  # or subclasses. Only the base class that establishes a new connection pool
57
63
  # with a call to `establish_connection` needs to be added.
64
+ #
65
+ # @param connection_class [Class]
66
+ # @return [void]
58
67
  def add_connection_class(connection_class)
59
- @lock.synchronize{ @connection_classes << connection_class }
68
+ @lock.synchronize { @connection_classes << connection_class }
60
69
  end
61
70
 
62
71
  # Return true if any connection is currently inside of a transaction.
72
+ #
73
+ # @return [Boolean]
63
74
  def in_transaction?
64
75
  connection_classes = [ActiveRecord::Base]
65
76
  unless @connection_classes.empty?
66
- connection_classes.concat(@lock.synchronize{ @connection_classes.to_a })
77
+ connection_classes.concat(@lock.synchronize { @connection_classes.to_a })
67
78
  end
68
79
  connection_classes.any? do |connection_class|
69
80
  connection_pool = connection_class.connection_pool
@@ -78,6 +89,8 @@ module Sidekiq
78
89
 
79
90
  # This method call needs to be wrapped around tests that use transactional fixtures.
80
91
  # It sets up data structures used to track the number of open transactions.
92
+ #
93
+ # @return [Object] the return value of the block
81
94
  def testing(&block)
82
95
  var = :sidekiq_rails_transaction_guard
83
96
  save_val = Thread.current[var]
@@ -93,6 +106,9 @@ module Sidekiq
93
106
  # class (see `add_connection_class` for more info). The current transaction level
94
107
  # for that class' connection will be set as the zero point. This method can only
95
108
  # be called inside a block wrapped with the `testing` method.
109
+ #
110
+ # @param connection_class [Class]
111
+ # @return [void]
96
112
  def set_allowed_transaction_level(connection_class)
97
113
  connection_counts = Thread.current[:sidekiq_rails_transaction_guard]
98
114
  unless connection_counts
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "sidekiq/transaction_guard"
@@ -3,18 +3,18 @@
3
3
  require_relative "lib/sidekiq/transaction_guard/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "sidekiq-transaction_guard"
7
- spec.version = Sidekiq::TransactionGuard::VERSION
8
- spec.authors = ["Brian Durand", "Winston Durand"]
9
- spec.email = ["bbdurand@gmail.com", "me@winstondurand.com"]
6
+ spec.name = "sidekiq-transaction_guard"
7
+ spec.version = Sidekiq::TransactionGuard::VERSION
8
+ spec.authors = ["Brian Durand", "Winston Durand"]
9
+ spec.email = ["bbdurand@gmail.com", "me@winstondurand.com"]
10
10
 
11
- spec.summary = "Protect from accidentally invoking Sidekiq jobs when there are open database transactions"
12
- spec.homepage = "https://github.com/bdurand/sidekiq-transaction_guard"
13
- spec.license = "MIT"
11
+ spec.summary = "Protect from accidentally invoking Sidekiq jobs when there are open database transactions"
12
+ spec.homepage = "https://github.com/bdurand/sidekiq-transaction_guard"
13
+ spec.license = "MIT"
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
16
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- ignore_files = %w(
17
+ ignore_files = %w[
18
18
  .gitignore
19
19
  .travis.yml
20
20
  Appraisals
@@ -23,23 +23,16 @@ Gem::Specification.new do |spec|
23
23
  Rakefile
24
24
  gemfiles/
25
25
  spec/
26
- )
27
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
- `git ls-files -z`.split("\x0").reject{ |f| ignore_files.any?{ |path| f.start_with?(path) } }
26
+ ]
27
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
29
29
  end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.required_ruby_version = '>= 2.2.2'
34
+ spec.required_ruby_version = ">= 2.2.2"
35
35
 
36
36
  spec.add_dependency "activerecord", ">= 4.0"
37
37
  spec.add_dependency "sidekiq", ">= 3.0"
38
-
39
- spec.add_development_dependency "bundler", "~> 1.10"
40
- spec.add_development_dependency "rake"
41
- spec.add_development_dependency "rspec", "~> 3.0"
42
- spec.add_development_dependency "database_cleaner"
43
- spec.add_development_dependency "sqlite3"
44
- spec.add_development_dependency "appraisal"
45
38
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-transaction_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  - Winston Durand
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-01-17 00:00:00.000000000 Z
12
+ date: 2023-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -39,91 +39,7 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '3.0'
42
- - !ruby/object:Gem::Dependency
43
- name: bundler
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '1.10'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '1.10'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: rspec
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '3.0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '3.0'
84
- - !ruby/object:Gem::Dependency
85
- name: database_cleaner
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: sqlite3
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- - !ruby/object:Gem::Dependency
113
- name: appraisal
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- description:
42
+ description:
127
43
  email:
128
44
  - bbdurand@gmail.com
129
45
  - me@winstondurand.com
@@ -131,6 +47,9 @@ executables: []
131
47
  extensions: []
132
48
  extra_rdoc_files: []
133
49
  files:
50
+ - ".github/dependabot.yml"
51
+ - ".github/workflows/continuous_integration.yml"
52
+ - ".standard.yml"
134
53
  - CHANGELOG.md
135
54
  - MIT_LICENSE.txt
136
55
  - README.md
@@ -145,7 +64,7 @@ homepage: https://github.com/bdurand/sidekiq-transaction_guard
145
64
  licenses:
146
65
  - MIT
147
66
  metadata: {}
148
- post_install_message:
67
+ post_install_message:
149
68
  rdoc_options: []
150
69
  require_paths:
151
70
  - lib
@@ -160,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
79
  - !ruby/object:Gem::Version
161
80
  version: '0'
162
81
  requirements: []
163
- rubygems_version: 3.0.3
164
- signing_key:
82
+ rubygems_version: 3.2.22
83
+ signing_key:
165
84
  specification_version: 4
166
85
  summary: Protect from accidentally invoking Sidekiq jobs when there are open database
167
86
  transactions