with_advisory_lock 3.2.0 → 4.0.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 +4 -4
- data/.travis.yml +4 -9
- data/Appraisals +8 -0
- data/Gemfile +2 -2
- data/README.md +5 -1
- data/gemfiles/activerecord_4.2.gemfile +3 -3
- data/gemfiles/activerecord_5.0.gemfile +1 -1
- data/gemfiles/activerecord_5.1.gemfile +2 -2
- data/gemfiles/activerecord_5.2.gemfile +19 -0
- data/lib/with_advisory_lock.rb +1 -1
- data/lib/with_advisory_lock/base.rb +3 -3
- data/lib/with_advisory_lock/concern.rb +2 -2
- data/lib/with_advisory_lock/database_adapter_support.rb +2 -2
- data/lib/with_advisory_lock/flock.rb +0 -1
- data/lib/with_advisory_lock/mysql.rb +3 -4
- data/lib/with_advisory_lock/nested_advisory_lock_error.rb +1 -1
- data/lib/with_advisory_lock/postgresql.rb +1 -2
- data/lib/with_advisory_lock/version.rb +1 -1
- data/test/minitest_helper.rb +0 -5
- data/test/parallelism_test.rb +4 -1
- data/with_advisory_lock.gemspec +3 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b0119f2158391cace745c0fa71a65497198de1
|
4
|
+
data.tar.gz: eb7f626ed7db658000ad0db260a2692035ee4dc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efe96bf02dc09cf167ed2058c164405c4f6d6ae9e31442b46d9e9f5ceebc7add1850861d0b6bd311087a056cab5928ad27afa680a4b11884d1474bee4ae25269
|
7
|
+
data.tar.gz: f9f753d910d24f6cb98fc91a47aed8dcccb82bf99f55ea193aceb8ffedf3c2732eef1c7945c64d1a5ac72aa27d89a0205307ddab72cce7113ca6c37c22496ac9
|
data/.travis.yml
CHANGED
@@ -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.
|
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
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 :
|
19
|
+
gemspec path: "../"
|
@@ -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: "../"
|
data/lib/with_advisory_lock.rb
CHANGED
@@ -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']
|
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
|
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
|
-
[
|
8
|
+
%i[mysql mysql2].include? @sym_name
|
9
9
|
end
|
10
10
|
|
11
11
|
def postgresql?
|
12
|
-
[
|
12
|
+
%i[postgresql empostgresql postgis].include? @sym_name
|
13
13
|
end
|
14
14
|
|
15
15
|
def sqlite?
|
@@ -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
|
-
|
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
|
@@ -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
|
-
|
data/test/minitest_helper.rb
CHANGED
@@ -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
|
data/test/parallelism_test.rb
CHANGED
@@ -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
|
67
|
+
end
|
65
68
|
|
66
69
|
it "doesn't create multiple duplicate rows with advisory locks" do
|
67
70
|
@use_advisory_lock = true
|
data/with_advisory_lock.gemspec
CHANGED
@@ -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:
|
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:
|
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: '
|
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: '
|
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:
|
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.
|
172
|
+
rubygems_version: 2.6.11
|
172
173
|
signing_key:
|
173
174
|
specification_version: 4
|
174
175
|
summary: Advisory locking for ActiveRecord
|