pg_lock 0.2.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e644648b686652e6f40413bd18485cc8ecc9dc255782ad3b26793230ff0730b
4
- data.tar.gz: de7e5592063b90ef9b3a5779b7877095fb31c0776749d5508cbec8f5a2f31291
3
+ metadata.gz: 1b5dc5c381b308116620ac170d1fe5f54d61d9cf73b0f7acbcb3d60b1cdc1222
4
+ data.tar.gz: fed6d8ba96c3afe22ff4cbe30b805f107e71452f133e8800b977e2aaf80c6756
5
5
  SHA512:
6
- metadata.gz: 321829a4a295725340247266fb2f869461f9d9e549cce0b36f9f736775e3a0a601f3224bbc23de7c15be89266e6156eb605d924f5d6d4ffafd156e05f700ea9d
7
- data.tar.gz: 155e96f2a5b5aedc38da672c5ea45d4c176d72188e17ab55614d6c7fce54bc171aa1e7e9ec8035e57225a48e5bf4bc2583998124cb5a158824a631f355346cbb
6
+ metadata.gz: c58e6e372c93b10afce883726ac72f6ca77a08bbb1e4971714ea076a3f5b4b5afb808d0c75a6a9d22d62d7f9a6fa373ff9dcc36cb428f922c10078d352616ffe
7
+ data.tar.gz: 3c77cdb4e29e139a2763062d6a9957225c3fe050cd6f376deb5c60cb47211edc86a7d11b03d84d543c645defc64d441718f3209591330e40d5c247acd3acce42
@@ -0,0 +1,13 @@
1
+
2
+ name: Check Changelog
3
+
4
+ on: [pull_request]
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v1
11
+ - name: Check that CHANGELOG is touched
12
+ run: |
13
+ cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # A Log of Changes!
2
2
 
3
- ## Master - unreleased
3
+ ## Main - unreleased
4
+
5
+ ## 1.0.0
6
+
7
+ - Fixed: Lock is now unlocked when an exception is raised in a log https://github.com/heroku/pg_lock/pull/17
8
+ - Changed: Removed mis-spelling of "aquired" https://github.com/heroku/pg_lock/pull/17
9
+
10
+ ## 0.3.0
11
+
12
+ - Fix method spelling (https://github.com/heroku/pg_lock/pull/16)
4
13
 
5
14
  ## 0.2.1
6
15
 
data/CODEOWNERS ADDED
@@ -0,0 +1,2 @@
1
+ # Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
2
+ #ECCN:Open Source
data/README.md CHANGED
@@ -119,13 +119,13 @@ ensure
119
119
  end
120
120
  ```
121
121
 
122
- You can check on the status of a lock with the `aquired?` method:
122
+ You can check on the status of a lock with the `acquired?` method:
123
123
 
124
124
  ```ruby
125
125
  begin
126
126
  lock = PgLock.new(name: "all_your_base")
127
127
  lock.create
128
- if lock.aquired?
128
+ if lock.acquired?
129
129
  # do stuff
130
130
  end
131
131
  ensure
@@ -11,7 +11,7 @@ class PgLock
11
11
 
12
12
  def lock
13
13
  @lock = connection.exec("select pg_try_advisory_lock($1,$2)", args)
14
- return aquired?
14
+ return acquired?
15
15
  end
16
16
 
17
17
  def unlock
@@ -19,23 +19,32 @@ class PgLock
19
19
  @lock = false
20
20
  end
21
21
 
22
- def aquired?
22
+ def acquired?
23
23
  TRUE_VALUES.include?(@lock[0]["pg_try_advisory_lock"])
24
24
  rescue
25
25
  false
26
26
  end
27
27
 
28
+ # Left the misspelled version of this method for backwards compatibility
29
+ def aquired?
30
+ acquired?
31
+ end
32
+
28
33
  def active?
29
- active = connection.exec(<<-eos, args).getvalue(0,0)
34
+ query = <<-eos
30
35
  SELECT granted
31
36
  FROM pg_locks
32
37
  WHERE locktype = 'advisory' AND
33
- pid = pg_backend_pid() AND
34
- mode = 'ExclusiveLock' AND
35
- classid = $1 AND
36
- objid = $2
38
+ pid = pg_backend_pid() AND
39
+ mode = 'ExclusiveLock' AND
40
+ classid = $1 AND
41
+ objid = $2
37
42
  eos
38
43
 
44
+ result = connection.exec(query, args)
45
+ return false if result.ntuples == 0
46
+
47
+ active = result.getvalue(0,0)
39
48
  TRUE_VALUES.include?(active)
40
49
  end
41
50
  end
@@ -1,3 +1,3 @@
1
1
  class PgLock
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/pg_lock.rb CHANGED
@@ -79,23 +79,27 @@ class PgLock
79
79
  end
80
80
  end
81
81
 
82
+ # Left the misspelled version of this method for backwards compatibility
82
83
  def aquired?
84
+ acquired?
85
+ end
86
+
87
+ def acquired?
83
88
  locket.active?
84
89
  end
85
- alias :has_lock? :aquired?
90
+
91
+ alias :has_lock? :acquired?
86
92
 
87
93
  private def internal_lock(&block)
88
94
  if create
89
95
  result = nil
90
- begin
91
- result = Timeout::timeout(ttl, &block) if block_given?
92
- ensure
93
- delete
94
- end
96
+ result = Timeout::timeout(ttl, &block) if block_given?
95
97
  return_result ? result : true
96
98
  else
97
99
  return NO_LOCK
98
100
  end
101
+ ensure
102
+ delete if locket.acquired?
99
103
  end
100
104
 
101
105
  private
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mikehale
8
8
  - schneems
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-12-03 00:00:00.000000000 Z
12
+ date: 2023-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
@@ -89,10 +89,12 @@ executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
+ - ".github/workflows/check_changelog.yml"
92
93
  - ".gitignore"
93
94
  - ".rspec"
94
95
  - ".travis.yml"
95
96
  - CHANGELOG.md
97
+ - CODEOWNERS
96
98
  - CODE_OF_CONDUCT.md
97
99
  - Gemfile
98
100
  - LICENSE.txt
@@ -108,7 +110,7 @@ homepage: http://github.com/heroku/pg_lock
108
110
  licenses:
109
111
  - MIT
110
112
  metadata: {}
111
- post_install_message:
113
+ post_install_message:
112
114
  rdoc_options: []
113
115
  require_paths:
114
116
  - lib
@@ -123,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  requirements: []
126
- rubygems_version: 3.0.3
127
- signing_key:
128
+ rubygems_version: 3.3.26
129
+ signing_key:
128
130
  specification_version: 4
129
131
  summary: Use Postgres advisory lock to isolate code execution across machines
130
132
  test_files: []