with_process_lock 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/lib/process_lock/version.rb +1 -1
- data/lib/process_lock/with_process_lock.rb +8 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af2c6f49c7b058970c7fc98be0949625b6f005d
|
4
|
+
data.tar.gz: '005991b9d6d6355c7c98e9ed0aa9241c3e2b147d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c34ceac06e7d7e8ffdb256a968a9e8464161fc742065cc3679ab5acdc19c810099c30f084f59940a746d913285509db1bc679426101d0296bc4e3ad6bd05eda
|
7
|
+
data.tar.gz: 6a700c32cff253497e62aa6e668b95b692ce359dbff3d5e5786154dd00687585ab2e89ea290a2df4164cf7bb23388c0adf73cda47693c3087117502ef25fa9c2
|
data/.gitignore
CHANGED
data/lib/process_lock/version.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
module ProcessLock
|
2
2
|
class WithProcessLock
|
3
|
+
|
3
4
|
def self.execute(key, &blk)
|
4
5
|
if can_execute?(key)
|
5
6
|
redis.set(key, true)
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
begin
|
8
|
+
yield blk
|
9
|
+
ensure
|
10
|
+
# Delete the key and quit redis even if the block raises an exception
|
11
|
+
redis.del(key)
|
12
|
+
redis.quit
|
13
|
+
end
|
9
14
|
else
|
10
15
|
redis.quit
|
11
16
|
raise StandardError, "Can not run process because #{key} taken."
|