locker 0.5.0 → 0.6.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
- SHA1:
3
- metadata.gz: 8ddf2a9f70dca510ad4dc728ce283dde0102e9a2
4
- data.tar.gz: 5c7d2bfa20e1642815fed9ffab42d2f7ed9b982f
2
+ SHA256:
3
+ metadata.gz: 6848498a3a915838b9b0df22e796e21ac1fdf39c36ffa0256d83a2e217c82d99
4
+ data.tar.gz: 816eb78e162302a315944f4863b5c5373a64f69e927af60ed8d4dd8299178f18
5
5
  SHA512:
6
- metadata.gz: b4ffe8ab76a4396b98292862e87837b82dd969aae85e55b02f3eab4cc0af582a95758dbc229dd027d38fd654539c1062ae7c868ab9fd791262585ee37459c836
7
- data.tar.gz: e2185e9144a35d2fcf6206d4fbf546cc73f0443e0531a78f2310b1d8aea6eaee64a9422c271187d11315e69cee1228c4b6ed05a87310d4aa64e0e98095ee6e17
6
+ metadata.gz: cc30fcb1130c337230549c235b8f7bb13bb66870a8e3a69e08e56a19cd330e52742cbb553718a6db8da3b48a0a1ddb4a087ff8c99b072ce346e7a2448f87fab1
7
+ data.tar.gz: 5cccbb2b52a857a052145498f9cad6001c05e8d19bb7b1eb3574ff9f1d908ffbb46af72456214814bdd2d9a0e31ad3c94a1ae419b39f7abdf07fafa091cf9769
@@ -0,0 +1 @@
1
+ ruby 2.5.5
@@ -2,14 +2,38 @@ language: ruby
2
2
  gemfile:
3
3
  - Gemfile_rails_3
4
4
  - Gemfile_rails_4
5
+ - Gemfile_rails_5
5
6
  rvm:
6
7
  - ruby-2.1.10
7
8
  - ruby-2.2.7
8
9
  - ruby-2.3.4
9
10
  - ruby-2.4.1
11
+ - ruby-2.5.5
10
12
  - jruby-9.1.9.0
11
13
  script: bundle exec rspec
12
14
  matrix:
13
15
  exclude:
14
16
  - rvm: ruby-2.4.1
15
17
  gemfile: Gemfile_rails_3
18
+ - rvm: ruby-2.1.10
19
+ gemfile: Gemfile_rails_5
20
+ - rvm: ruby-2.2.7
21
+ gemfile: Gemfile_rails_5
22
+ - rvm: ruby-2.3.4
23
+ gemfile: Gemfile_rails_5
24
+ - rvm: ruby-2.4.1
25
+ gemfile: Gemfile_rails_5
26
+ - rvm: ruby-2.5.5
27
+ gemfile: Gemfile_rails_3
28
+ - rvm: ruby-2.5.5
29
+ gemfile: Gemfile_rails_4
30
+ - rvm: jruby-9.1.9.0
31
+ gemfile: Gemfile_rails_5
32
+ services:
33
+ - postgresql
34
+ addons:
35
+ postgresql: "10"
36
+ apt:
37
+ packages:
38
+ - postgresql-10
39
+ - postgresql-client-10
data/Gemfile CHANGED
@@ -1,17 +1,17 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", ">=3.2", "<5"
3
+ gem "activerecord", ">=3.2", "<6"
4
4
 
5
5
  group :development, :test do
6
6
  platform :ruby do
7
- gem "pg"
8
- gem "pry", "~> 0.10.4"
9
- gem "pry-byebug", "~> 3.4.2"
7
+ gem "pg", "~> 0.21.0", "< 1.0"
8
+ gem "pry", "~> 0.13.1"
9
+ gem "pry-byebug", "~> 3.9.0"
10
10
  end
11
11
 
12
12
  platform :jruby do
13
- gem 'activerecord-jdbcpostgresql-adapter'
13
+ gem 'activerecord-jdbcpostgresql-adapter', '= 1.3.25'
14
14
  end
15
15
 
16
- gem "rspec", "~> 3.2.0"
16
+ gem "rspec", "~> 3.9.0"
17
17
  end
@@ -4,13 +4,13 @@ gem "activerecord", ">=3.2", "<4"
4
4
 
5
5
  group :development, :test do
6
6
  platform :ruby do
7
- gem "pg"
7
+ gem "pg", "< 1.0"
8
8
  gem "pry", "~> 0.10.4"
9
9
  gem "pry-byebug", "~> 3.4.2"
10
10
  end
11
11
 
12
12
  platform :jruby do
13
- gem 'activerecord-jdbcpostgresql-adapter'
13
+ gem 'activerecord-jdbcpostgresql-adapter', '= 1.3.25'
14
14
  end
15
15
 
16
16
  gem "rspec", "~> 3.2.0"
@@ -4,13 +4,13 @@ gem "activerecord", ">=4", "<5"
4
4
 
5
5
  group :development, :test do
6
6
  platform :ruby do
7
- gem "pg"
7
+ gem "pg", "< 1.0"
8
8
  gem "pry", "~> 0.10.4"
9
9
  gem "pry-byebug", "~> 3.4.2"
10
10
  end
11
11
 
12
12
  platform :jruby do
13
- gem 'activerecord-jdbcpostgresql-adapter'
13
+ gem 'activerecord-jdbcpostgresql-adapter', '= 1.3.25'
14
14
  end
15
15
 
16
16
  gem "rspec", "~> 3.2.0"
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "~> 5"
4
+
5
+ group :development, :test do
6
+ platform :ruby do
7
+ gem "pg", "~> 0.21.0", "< 1.0"
8
+ gem "pry", "~> 0.13.1"
9
+ gem "pry-byebug", "~> 3.9.0"
10
+ end
11
+
12
+ platform :jruby do
13
+ gem 'activerecord-jdbcpostgresql-adapter', "~> 50"
14
+ end
15
+
16
+ gem "rspec", "~> 3.9.0"
17
+ end
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Locker is a locking mechanism for limiting the concurrency of ruby code using the database.
4
4
 
5
- Locker is dependent on Postgres and the ActiveRecord (>= 3.2.0) gem.
5
+ Locker is dependent on Postgres and the ActiveRecord (>= 3.2.0 and < 6.0) gem.
6
6
 
7
7
  ## Supported Rubies
8
8
 
@@ -6,8 +6,12 @@ class Locker
6
6
 
7
7
  attr_reader :key, :crc, :lockspace, :blocking, :locked
8
8
 
9
+ # The advisory function we use from PostgreSQL needs the arguments to be
10
+ # INT, therefore this are the range of int numbers for PostgreSQL
9
11
  MAX_LOCK = 2147483647
10
12
  MIN_LOCK = -2147483648
13
+
14
+ # Max number that a 32bit computer can hold
11
15
  OVERFLOW_ADJUSTMENT = 2**32
12
16
 
13
17
  def initialize(key, options={})
@@ -83,7 +87,13 @@ class Locker
83
87
  protected
84
88
 
85
89
  def get(connection)
86
- result = exec_query(connection, "SELECT pg_try_advisory_xact_lock(#{connection.quote(@lockspace)}, #{connection.quote(@crc)})")
90
+ lockspace_quote = connection.quote(@lockspace)
91
+ crc_quote = connection.quote(@crc)
92
+
93
+ result = exec_query(
94
+ connection,
95
+ "SELECT pg_try_advisory_xact_lock(#{lockspace_quote}, #{crc_quote})"
96
+ )
87
97
  @locked = successful_result?(result)
88
98
  end
89
99
 
@@ -94,6 +104,8 @@ class Locker
94
104
  end
95
105
  end
96
106
 
107
+ # CRC32 digest to get a decimal numeric of the key used, make sure the
108
+ # resulting number is within PostgreSql max and min Integer numbers
97
109
  def convert_to_crc(key)
98
110
  crc = Zlib.crc32(key)
99
111
  crc -= OVERFLOW_ADJUSTMENT if crc > MAX_LOCK
@@ -101,7 +113,11 @@ class Locker
101
113
  end
102
114
 
103
115
  def successful_result?(result)
104
- result.rows.size == 1 && result.rows[0].size == 1 && result.rows[0][0] == "t"
116
+ result.rows.size == 1 &&
117
+ result.rows[0].size == 1 && (
118
+ result.rows[0][0] == 't' || # Checking for old ActiveRecord
119
+ result.rows[0][0].class == TrueClass # Checking for the value true
120
+ )
105
121
  end
106
122
 
107
123
  def exec_query(connection, query)
@@ -1,3 +1,3 @@
1
1
  class Locker
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -1,5 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
3
2
  require "locker/version"
4
3
 
5
4
  Gem::Specification.new do |s|
@@ -7,8 +6,8 @@ Gem::Specification.new do |s|
7
6
  s.version = Locker::VERSION
8
7
  s.authors = ["Nathan Sutton", "Justin Greer"]
9
8
  s.email = ["nate@zencoder.com", "justin@zencoder.com"]
10
- s.summary = %q{Locker is a locking mechanism for limiting the concurrency of ruby code using the database.}
11
- s.description = %q{Locker is a locking mechanism for limiting the concurrency of ruby code using the database. It presently only works with PostgreSQL.}
9
+ s.summary = 'Locker is a locking mechanism for limiting the concurrency of ruby code using the database.'
10
+ s.description = 'Locker is a locking mechanism for limiting the concurrency of ruby code using the database. It presently only works with PostgreSQL.'
12
11
 
13
12
  s.rubyforge_project = "locker"
14
13
 
@@ -16,9 +15,9 @@ Gem::Specification.new do |s|
16
15
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
16
  s.require_paths = ["lib"]
18
17
 
19
- s.add_dependency "activerecord", ">=3.2", "<5"
20
- s.add_development_dependency "pg", "~> 0"
21
- s.add_development_dependency "rspec", "~> 3.2"
18
+ s.add_dependency "activerecord", ">=3.2", "< 6"
19
+ s.add_development_dependency "pg", "~> 0", "< 1"
22
20
  s.add_development_dependency "pry", "~> 0.10.4"
23
21
  s.add_development_dependency "pry-byebug", "~> 3.4.2"
22
+ s.add_development_dependency "rspec", "~> 3.2"
24
23
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sutton
8
8
  - Justin Greer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-04 00:00:00.000000000 Z
12
+ date: 2020-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '3.2'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5'
23
+ version: '6'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '3.2'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5'
33
+ version: '6'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: pg
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,9 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
41
44
  type: :development
42
45
  prerelease: false
43
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -45,48 +48,51 @@ dependencies:
45
48
  - - "~>"
46
49
  - !ruby/object:Gem::Version
47
50
  version: '0'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '1'
48
54
  - !ruby/object:Gem::Dependency
49
- name: rspec
55
+ name: pry
50
56
  requirement: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '3.2'
60
+ version: 0.10.4
55
61
  type: :development
56
62
  prerelease: false
57
63
  version_requirements: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.2'
67
+ version: 0.10.4
62
68
  - !ruby/object:Gem::Dependency
63
- name: pry
69
+ name: pry-byebug
64
70
  requirement: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: 0.10.4
74
+ version: 3.4.2
69
75
  type: :development
70
76
  prerelease: false
71
77
  version_requirements: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: 0.10.4
81
+ version: 3.4.2
76
82
  - !ruby/object:Gem::Dependency
77
- name: pry-byebug
83
+ name: rspec
78
84
  requirement: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: 3.4.2
88
+ version: '3.2'
83
89
  type: :development
84
90
  prerelease: false
85
91
  version_requirements: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: 3.4.2
95
+ version: '3.2'
90
96
  description: Locker is a locking mechanism for limiting the concurrency of ruby code
91
97
  using the database. It presently only works with PostgreSQL.
92
98
  email:
@@ -97,13 +103,13 @@ extensions: []
97
103
  extra_rdoc_files: []
98
104
  files:
99
105
  - ".gitignore"
100
- - ".ruby-gemset"
101
- - ".ruby-version"
106
+ - ".tool-versions"
102
107
  - ".travis.yml"
103
108
  - CHANGELOG.md
104
109
  - Gemfile
105
110
  - Gemfile_rails_3
106
111
  - Gemfile_rails_4
112
+ - Gemfile_rails_5
107
113
  - LICENSE
108
114
  - README.md
109
115
  - Rakefile
@@ -123,10 +129,10 @@ files:
123
129
  - spec/locker/advisory_spec.rb
124
130
  - spec/locker/locker_spec.rb
125
131
  - spec/spec_helper.rb
126
- homepage:
132
+ homepage:
127
133
  licenses: []
128
134
  metadata: {}
129
- post_install_message:
135
+ post_install_message:
130
136
  rdoc_options: []
131
137
  require_paths:
132
138
  - lib
@@ -142,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
148
  version: '0'
143
149
  requirements: []
144
150
  rubyforge_project: locker
145
- rubygems_version: 2.6.2
146
- signing_key:
151
+ rubygems_version: 2.7.6.2
152
+ signing_key:
147
153
  specification_version: 4
148
154
  summary: Locker is a locking mechanism for limiting the concurrency of ruby code using
149
155
  the database.
@@ -1 +0,0 @@
1
- locker
@@ -1 +0,0 @@
1
- ruby-2.2.1