pg_lock 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: e285d50b50c70bd26a8e9ce0047cb874450ebc27dc5db28c903ef613540ecaed
4
- data.tar.gz: 8a167c46ae260ac9b84e0dd442f821a7d3a9894a4a72f206cb5fd669fcbf4594
3
+ metadata.gz: c92e38fab7329deb1a573eafce48291e38b3198baf0ce39a4500d305a1b01081
4
+ data.tar.gz: 3c14d574202f72524728cc3f1ffb5af3d2dc16b6980bfa9efe130fa84a6f5c00
5
5
  SHA512:
6
- metadata.gz: 23e058530b6b4029df92d8733ab7828753360c85092113a1dac14afab03ff8de6a1c926c8399a7f6833811b3963febd75bb1aeaefdfb8827ab3e44c13964e7e4
7
- data.tar.gz: 7346e5463867c3a5755203c6c8e397e863d1d2756eeda5db4614dc525693d758270e02a9bb4b6ec8e686565410cec011f7be1657d480f5fcf1d35314bb0366a2
6
+ metadata.gz: 67be6b9ef5ff32f10cd6f8a98d6b58af010c9d03e480617372c6e43787fbdeb704d349d573d22b1e2eb7fa4c6a05c97106f6b30a7e3ff72f6247a73cba63d781
7
+ data.tar.gz: 17efa281393055a6facdfb44bbca361a49f00ae20454fe3557c89d3e971aeb0e6b7c742609409d6080345814bf8bc0d8ad1c09fb465d9dcacb2d37d5cd548013
data/.travis.yml CHANGED
@@ -1,18 +1,21 @@
1
1
  language: ruby
2
+ services:
3
+ - postgresql
2
4
  rvm:
3
- - 2.1
4
- - 2.2
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
5
8
  - ruby-head
6
9
 
7
10
  script:
8
11
  - bundle exec rspec spec
9
12
 
13
+ before_install:
14
+ - gem install bundler
15
+
10
16
  before_script:
11
17
  - psql -c 'create database pg_lock_test;' -U postgres
12
18
 
13
- addons:
14
- postgresql: "9.3"
15
-
16
19
  matrix:
17
20
  allow_failures:
18
21
  - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # A Log of Changes!
2
2
 
3
+ ## Master - unreleased
4
+
5
+ ## 0.2.0
6
+
7
+ - Return the result evaluated inside the block (https://github.com/heroku/pg_lock/pull/10)
8
+
3
9
  ## [0.1.2] - 2017-12-06
4
10
 
5
11
  - Support Rails 5 and newer PG versions [#5]
@@ -1,3 +1,3 @@
1
1
  class PgLock
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/pg_lock.rb CHANGED
@@ -27,12 +27,13 @@ class PgLock
27
27
  end
28
28
  UnableToLock = UnableToLockError
29
29
 
30
- def initialize(name:, attempts: 3, attempt_interval: 1, ttl: 60, connection: DEFAULT_CONNECTION_CONNECTOR.call, log: DEFAULT_LOGGER.call )
30
+ def initialize(name:, attempts: 3, attempt_interval: 1, ttl: 60, connection: DEFAULT_CONNECTION_CONNECTOR.call, log: DEFAULT_LOGGER.call, return_result: true)
31
31
  self.name = name
32
32
  self.max_attempts = [attempts, 1].max
33
33
  self.attempt_interval = attempt_interval
34
34
  self.ttl = ttl || 0 # set this to 0 to disable the timeout
35
35
  self.log = log
36
+ self.return_result = return_result
36
37
 
37
38
  connection or raise "Must provide a valid connection object"
38
39
  self.locket = Locket.new(connection, [PG_LOCK_SPACE, key(name)])
@@ -41,12 +42,13 @@ class PgLock
41
42
  # Runs the given block if an advisory lock is able to be acquired.
42
43
  def lock(&block)
43
44
  if create
45
+ result = nil
44
46
  begin
45
- Timeout::timeout(ttl, &block) if block_given?
47
+ result = Timeout::timeout(ttl, &block) if block_given?
46
48
  ensure
47
49
  delete
48
50
  end
49
- return true
51
+ return_result ? result : true
50
52
  else
51
53
  return false
52
54
  end
@@ -97,6 +99,7 @@ class PgLock
97
99
  attr_accessor :ttl
98
100
  attr_accessor :name
99
101
  attr_accessor :log
102
+ attr_accessor :return_result
100
103
 
101
104
  def key(name)
102
105
  i = Zlib.crc32(name.to_s)
data/pg_lock.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "pg", ">= 0.15"
23
23
  spec.add_development_dependency "activerecord", ">= 2.3"
24
- spec.add_development_dependency "bundler", "~> 1"
24
+ spec.add_development_dependency "bundler", "~> 2"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
 
27
27
  spec.add_development_dependency "rspec", "~> 3.1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mikehale
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-12-06 00:00:00.000000000 Z
12
+ date: 2019-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1'
48
+ version: '2'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1'
55
+ version: '2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.6.14
126
+ rubygems_version: 3.0.3
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: Use Postgres advisory lock to isolate code execution across machines