just_one_lock 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 96a82fccd7eba5bb06192f7ebd10819e794321b6
4
- data.tar.gz: e4792fd094d7a23b6571b638fbb838c9b3a80c36
3
+ metadata.gz: 3e557230f996c20dc4ce8d926ce91ec498c69b16
4
+ data.tar.gz: 13a29e9beafc7e7bf698e354209a34379c32ae13
5
5
  SHA512:
6
- metadata.gz: b370ad55949836b9c1177dabe8e09c838003ec2195a27edfbf606d8457db8f8670a90f183b6932353b0a611e26ed6df7ed35953888aeca33dfe6e093c6c8c527
7
- data.tar.gz: c9708ea092dda6892be69665277c0adace654ed86bd046e9a20fe8704e177b6c592b42f546f8983facaaddeedc8e0530c08a059c2571d32ffcc68a2bf46c56ee
6
+ metadata.gz: 0aa440f661bc1a5dfd94399b34b163b262f2d6dada1c816e8eaf73c63c055f332a56a0cb31382c976c92faf34738d97931c3d6824a30bd23b3d6fe76020fbf3d
7
+ data.tar.gz: fe426d149e1881bde672fd6d32b454f2641687ccf9421d8172661dc391ef2b3e1f2589d9c583059cf63e61207757d781d8e7a38009f0a1e27f32387e7a4be763
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- just_one_lock (0.0.3)
4
+ just_one_lock (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,7 +2,6 @@ require 'timeout'
2
2
 
3
3
  module JustOneLock::Blocking
4
4
  DEFAULT_TIMEOUT = 1
5
- class AlreadyLocked < StandardError; end
6
5
 
7
6
  def self.filelock(
8
7
  lockname,
@@ -12,7 +11,7 @@ module JustOneLock::Blocking
12
11
  )
13
12
  result = nil
14
13
  File.open(lockname, File::RDWR|File::CREAT, 0644) do |f|
15
- Timeout::timeout(timeout, JustOneLock::Blocking::AlreadyLocked) { f.flock(File::LOCK_EX) }
14
+ Timeout::timeout(timeout, JustOneLock::AlreadyLocked) { f.flock(File::LOCK_EX) }
16
15
 
17
16
  result = JustOneLock.run(f, lockname, &block)
18
17
  end
@@ -34,8 +33,8 @@ module JustOneLock::Blocking
34
33
 
35
34
  begin
36
35
  return filelock(lock_path, timeout: timeout, delete_files: delete_files, &block)
37
- rescue JustOneLock::Blocking::AlreadyLocked => e
38
- output.puts "Another process <#{scope}> already is running"
36
+ rescue JustOneLock::AlreadyLocked => e
37
+ JustOneLock.already_locked(output, scope)
39
38
  end
40
39
  end
41
40
  end
@@ -27,10 +27,10 @@ module JustOneLock::NonBlocking
27
27
  scope_name = scope.gsub(':', '_')
28
28
  lock_path = File.join(lock_dir, scope_name + '.lock')
29
29
 
30
- was_executed = filelock(lock_path, delete_files: delete_files, &block)
31
-
32
- unless was_executed
33
- output.puts "Another process <#{scope}> already is running"
30
+ begin
31
+ return filelock(lock_path, delete_files: delete_files, &block)
32
+ rescue JustOneLock::AlreadyLocked => e
33
+ JustOneLock.already_locked(output, scope)
34
34
  end
35
35
  end
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module JustOneLock
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/just_one_lock.rb CHANGED
@@ -3,6 +3,8 @@ require 'just_one_lock/blocking'
3
3
  require 'just_one_lock/non_blocking'
4
4
 
5
5
  module JustOneLock
6
+ class AlreadyLocked < StandardError; end
7
+
6
8
  class NullStream
7
9
  class << self
8
10
  def puts(str); end
@@ -30,6 +32,12 @@ module JustOneLock
30
32
  @files.keys
31
33
  end
32
34
 
35
+ def self.already_locked(output, scope)
36
+ msg = "Another process <#{scope}> already is running"
37
+ output.puts msg
38
+ raise JustOneLock::AlreadyLocked, msg
39
+ end
40
+
33
41
  private
34
42
 
35
43
  def self.write_pid(f)
@@ -77,7 +77,7 @@ shared_examples 'a locking object' do
77
77
  JustOneLock::Blocking.filelock lockpath, timeout: 0.001 do
78
78
  answer = 0
79
79
  end
80
- end.to raise_error(JustOneLock::Blocking::AlreadyLocked)
80
+ end.to raise_error(JustOneLock::AlreadyLocked)
81
81
 
82
82
  expect(answer).to eq(42)
83
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: just_one_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stankiewicz, Yury Kotov