with_advisory_lock 3.2.0 → 4.0.0

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: e94aa36a41376cf160850770d5a49a3d301aea4e
4
- data.tar.gz: 1e7ac3e6f61566a8e2fd1da766c762405f8a7502
3
+ metadata.gz: 82b0119f2158391cace745c0fa71a65497198de1
4
+ data.tar.gz: eb7f626ed7db658000ad0db260a2692035ee4dc1
5
5
  SHA512:
6
- metadata.gz: 002a011573e173b6957fc7b51023274ed7f34032f2502def7b6b1c9219aa34979552fda5a615816d3b4be246c083a7d9a8d1e71e9bb324a88183ae4a354bdc36
7
- data.tar.gz: f30b67b87759cf3c085b96e995e9788728c956b1f74f585d5a198100840d65bc427d6844df99420bacf17d3c4dfbc8b108c77cf4b0ca8bc54a03aec1214991b5
6
+ metadata.gz: efe96bf02dc09cf167ed2058c164405c4f6d6ae9e31442b46d9e9f5ceebc7add1850861d0b6bd311087a056cab5928ad27afa680a4b11884d1474bee4ae25269
7
+ data.tar.gz: f9f753d910d24f6cb98fc91a47aed8dcccb82bf99f55ea193aceb8ffedf3c2732eef1c7945c64d1a5ac72aa27d89a0205307ddab72cce7113ca6c37c22496ac9
@@ -4,11 +4,13 @@ dist: trusty
4
4
  sudo: required
5
5
 
6
6
  rvm:
7
+ - 2.5.1
7
8
  - 2.4.0
8
9
  - 2.3.3
9
- - 2.2.6
10
+ - 2.2.10
10
11
 
11
12
  gemfile:
13
+ - gemfiles/activerecord_5.2.gemfile
12
14
  - gemfiles/activerecord_5.1.gemfile
13
15
  - gemfiles/activerecord_5.0.gemfile
14
16
  - gemfiles/activerecord_4.2.gemfile
@@ -27,11 +29,4 @@ script: WITH_ADVISORY_LOCK_PREFIX=$TRAVIS_JOB_ID bundle exec rake --trace
27
29
  before_script:
28
30
  - bash .travis.install-mysql-5.7.sh
29
31
  - mysql -e 'create database with_advisory_lock_test'
30
- - psql -c 'create database with_advisory_lock_test' -U postgres
31
-
32
- matrix:
33
- allow_failures:
34
- - gemfile: gemfiles/activerecord_edge.gemfile
35
- - rvm: jruby-19mode # travis' version of jruby has issues. Tests pass with jruby 1.7.13/java 1.8.0_11 on mac.
36
- - rvm: rbx-2
37
-
32
+ - psql -c 'create database with_advisory_lock_test' -U postgres
data/Appraisals CHANGED
@@ -1,5 +1,9 @@
1
1
  appraise "activerecord-4.2" do
2
2
  gem "activerecord", "~> 4.2.0"
3
+ platforms :ruby do
4
+ gem "pg", "~> 0.21"
5
+ gem "mysql2", "< 0.5"
6
+ end
3
7
  end
4
8
 
5
9
  appraise "activerecord-5.0" do
@@ -9,3 +13,7 @@ end
9
13
  appraise "activerecord-5.1" do
10
14
  gem "activerecord", "~> 5.1.0"
11
15
  end
16
+
17
+ appraise "activerecord-5.2" do
18
+ gem "activerecord", "~> 5.1.0"
19
+ end
data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  platforms :ruby do
6
- gem 'mysql2', '~> 0.3.10' # Rails 3.2 requires 0.3.x
7
- gem 'pg', '< 0.19' # 0.19 requires Ruby 2.0+
6
+ gem 'mysql2'
7
+ gem 'pg'
8
8
  gem 'sqlite3'
9
9
  end
10
10
 
data/README.md CHANGED
@@ -158,10 +158,14 @@ end
158
158
 
159
159
  ## Changelog
160
160
 
161
+ ### 4.0.0
162
+
163
+ * Drop support for unsupported versions of activerecord
164
+ * Drop support for unsupported versions of ruby
165
+
161
166
  ### 3.2.0
162
167
 
163
168
  * [Joshua Flanagan](https://github.com/joshuaflanagan) [added a SQL comment to the lock query for PostgreSQL](https://github.com/ClosureTree/with_advisory_lock/pull/28). Thanks!
164
-
165
169
  * [Fernando Luizão](https://github.com/fernandoluizao) found a spurious requirement for `thread_safe`. Thanks for the [fix](https://github.com/ClosureTree/with_advisory_lock/pull/27)!
166
170
 
167
171
  ### 3.1.1
@@ -5,8 +5,8 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 4.2.0"
6
6
 
7
7
  platforms :ruby do
8
- gem "mysql2"
9
- gem "pg"
8
+ gem "mysql2", "< 0.5"
9
+ gem "pg", "~> 0.21"
10
10
  gem "sqlite3"
11
11
  end
12
12
 
@@ -16,4 +16,4 @@ platforms :jruby do
16
16
  gem "activerecord-jdbcsqlite3-adapter"
17
17
  end
18
18
 
19
- gemspec :path => "../"
19
+ gemspec path: "../"
@@ -16,4 +16,4 @@ platforms :jruby do
16
16
  gem "activerecord-jdbcsqlite3-adapter"
17
17
  end
18
18
 
19
- gemspec :path => "../"
19
+ gemspec path: "../"
@@ -5,8 +5,8 @@ source "https://rubygems.org"
5
5
  gem "activerecord", "~> 5.1.0"
6
6
 
7
7
  platforms :ruby do
8
- gem "mysql2", "~> 0.3.10"
9
- gem "pg", "< 0.19"
8
+ gem "mysql2"
9
+ gem "pg"
10
10
  gem "sqlite3"
11
11
  end
12
12
 
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1.0"
6
+
7
+ platforms :ruby do
8
+ gem "mysql2"
9
+ gem "pg"
10
+ gem "sqlite3"
11
+ end
12
+
13
+ platforms :jruby do
14
+ gem "activerecord-jdbcmysql-adapter"
15
+ gem "activerecord-jdbcpostgresql-adapter"
16
+ gem "activerecord-jdbcsqlite3-adapter"
17
+ end
18
+
19
+ gemspec path: "../"
@@ -14,5 +14,5 @@ module WithAdvisoryLock
14
14
  end
15
15
 
16
16
  ActiveSupport.on_load :active_record do
17
- ActiveRecord::Base.send :include, WithAdvisoryLock::Concern
17
+ include WithAdvisoryLock::Concern
18
18
  end
@@ -22,7 +22,7 @@ module WithAdvisoryLock
22
22
  attr_reader :connection, :lock_name, :timeout_seconds, :shared, :transaction
23
23
 
24
24
  def initialize(connection, lock_name, options)
25
- options = {timeout_seconds: options} unless options.respond_to?(:fetch)
25
+ options = { timeout_seconds: options } unless options.respond_to?(:fetch)
26
26
  options.assert_valid_keys :timeout_seconds, :shared, :transaction
27
27
 
28
28
  @connection = connection
@@ -33,7 +33,7 @@ module WithAdvisoryLock
33
33
  end
34
34
 
35
35
  def lock_str
36
- @lock_str ||= "#{ENV['WITH_ADVISORY_LOCK_PREFIX'].to_s}#{lock_name.to_s}"
36
+ @lock_str ||= "#{ENV['WITH_ADVISORY_LOCK_PREFIX']}#{lock_name}"
37
37
  end
38
38
 
39
39
  def lock_stack_item
@@ -72,7 +72,7 @@ module WithAdvisoryLock
72
72
 
73
73
  def yield_with_lock_and_timeout(&block)
74
74
  give_up_at = Time.now + @timeout_seconds if @timeout_seconds
75
- while @timeout_seconds.nil? || Time.now < give_up_at do
75
+ while @timeout_seconds.nil? || Time.now < give_up_at
76
76
  r = yield_with_lock(&block)
77
77
  return r if r.lock_was_acquired?
78
78
  # Randomizing sleep time may help reduce contention.
@@ -6,12 +6,12 @@ module WithAdvisoryLock
6
6
  delegate :with_advisory_lock, :advisory_lock_exists?, to: 'self.class'
7
7
 
8
8
  module ClassMethods
9
- def with_advisory_lock(lock_name, options={}, &block)
9
+ def with_advisory_lock(lock_name, options = {}, &block)
10
10
  result = with_advisory_lock_result(lock_name, options, &block)
11
11
  result.lock_was_acquired? ? result.result : false
12
12
  end
13
13
 
14
- def with_advisory_lock_result(lock_name, options={}, &block)
14
+ def with_advisory_lock_result(lock_name, options = {}, &block)
15
15
  impl = impl_class.new(connection, lock_name, options)
16
16
  impl.with_advisory_lock_if_needed(&block)
17
17
  end
@@ -5,11 +5,11 @@ module WithAdvisoryLock
5
5
  end
6
6
 
7
7
  def mysql?
8
- [:mysql, :mysql2].include? @sym_name
8
+ %i[mysql mysql2].include? @sym_name
9
9
  end
10
10
 
11
11
  def postgresql?
12
- [:postgresql, :empostgresql, :postgis].include? @sym_name
12
+ %i[postgresql empostgresql postgis].include? @sym_name
13
13
  end
14
14
 
15
15
  def sqlite?
@@ -2,7 +2,6 @@ require 'fileutils'
2
2
 
3
3
  module WithAdvisoryLock
4
4
  class Flock < Base
5
-
6
5
  def filename
7
6
  @filename ||= begin
8
7
  safe = lock_str.to_s.gsub(/[^a-z0-9]/i, '')
@@ -5,11 +5,10 @@ module WithAdvisoryLock
5
5
  unless lock_stack.empty?
6
6
  raise NestedAdvisoryLockError.new(
7
7
  "MySQL doesn't support nested Advisory Locks",
8
- lock_stack.dup)
9
- end
10
- if shared
11
- raise ArgumentError, 'shared locks are not supported on MySQL'
8
+ lock_stack.dup
9
+ )
12
10
  end
11
+ raise ArgumentError, 'shared locks are not supported on MySQL' if shared
13
12
  if transaction
14
13
  raise ArgumentError, 'transaction level locks are not supported on MySQL'
15
14
  end
@@ -8,7 +8,7 @@ module WithAdvisoryLock
8
8
  end
9
9
 
10
10
  def to_s
11
- super + (lock_stack ? ": lock stack = #{lock_stack}" : "")
11
+ super + (lock_stack ? ": lock stack = #{lock_stack}" : '')
12
12
  end
13
13
  end
14
14
  end
@@ -21,7 +21,7 @@ module WithAdvisoryLock
21
21
  end
22
22
 
23
23
  def execute_successful?(pg_function)
24
- comment = lock_name.gsub(/(\/\*)|(\*\/)/, "--")
24
+ comment = lock_name.gsub(/(\/\*)|(\*\/)/, '--')
25
25
  sql = "SELECT #{pg_function}(#{lock_keys.join(',')}) AS #{unique_column_name} /* #{comment} */"
26
26
  result = connection.select_value(sql)
27
27
  # MRI returns 't', jruby returns true. YAY!
@@ -39,4 +39,3 @@ module WithAdvisoryLock
39
39
  end
40
40
  end
41
41
  end
42
-
@@ -1,3 +1,3 @@
1
1
  module WithAdvisoryLock
2
- VERSION = Gem::Version.new('3.2.0')
2
+ VERSION = Gem::Version.new('4.0.0')
3
3
  end
@@ -24,11 +24,6 @@ rescue LoadError
24
24
  end
25
25
  require 'minitest/autorun'
26
26
  require 'minitest/great_expectations'
27
- if ActiveRecord::VERSION::MAJOR > 3
28
- # minitest-reporters-1.0.5/lib/minitest/old_activesupport_fix.rb:7:in `remove_method': method `run' not defined in ActiveSupport::Testing::SetupAndTeardown::ForMinitest (NameError)
29
- require 'minitest/reporters'
30
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
31
- end
32
27
  require 'mocha/setup'
33
28
 
34
29
  class MiniTest::Spec
@@ -54,14 +54,17 @@ describe 'parallelism' do
54
54
  @workers = 10
55
55
  end
56
56
 
57
+ # < SQLite, understandably, throws "The database file is locked (database is locked)"
58
+
57
59
  it 'creates multiple duplicate rows without advisory locks' do
60
+ skip if env_db == :sqlite
58
61
  @use_advisory_lock = false
59
62
  @iterations = 1
60
63
  run_workers
61
64
  Tag.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
62
65
  TagAudit.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
63
66
  Label.all.size.must_be :>, @iterations # <- any duplicated rows will make me happy.
64
- end unless env_db == :sqlite # < SQLite, understandably, throws "The database file is locked (database is locked)"
67
+ end
65
68
 
66
69
  it "doesn't create multiple duplicate rows with advisory locks" do
67
70
  @use_advisory_lock = true
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'with_advisory_lock/version'
@@ -14,11 +13,12 @@ Gem::Specification.new do |gem|
14
13
  gem.license = 'MIT'
15
14
 
16
15
  gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
16
  gem.test_files = gem.files.grep(%r{^test/})
19
17
  gem.require_paths = %w(lib)
18
+ gem.required_ruby_version = '>= 2.2.10'
19
+
20
+ gem.add_runtime_dependency 'activerecord', '>= 4.2'
20
21
 
21
- gem.add_runtime_dependency 'activerecord', '>= 3.2'
22
22
 
23
23
  gem.add_development_dependency 'yard'
24
24
  gem.add_development_dependency 'minitest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_advisory_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew McEachen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-06 00:00:00.000000000 Z
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '4.2'
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
- version: '3.2'
26
+ version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +126,7 @@ files:
126
126
  - gemfiles/activerecord_4.2.gemfile
127
127
  - gemfiles/activerecord_5.0.gemfile
128
128
  - gemfiles/activerecord_5.1.gemfile
129
+ - gemfiles/activerecord_5.2.gemfile
129
130
  - lib/with_advisory_lock.rb
130
131
  - lib/with_advisory_lock/base.rb
131
132
  - lib/with_advisory_lock/concern.rb
@@ -160,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
161
  requirements:
161
162
  - - ">="
162
163
  - !ruby/object:Gem::Version
163
- version: '0'
164
+ version: 2.2.10
164
165
  required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  requirements:
166
167
  - - ">="
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  version: '0'
169
170
  requirements: []
170
171
  rubyforge_project:
171
- rubygems_version: 2.6.8
172
+ rubygems_version: 2.6.11
172
173
  signing_key:
173
174
  specification_version: 4
174
175
  summary: Advisory locking for ActiveRecord