futex 0.7.0 → 0.8.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: b6b80bd02f4bb99bf83264c534c6c9f13265e11acd484cb389f75fbfbc809650
4
- data.tar.gz: a599ea5bd0024323fbaed93313985e424b16c8d2468a44809e2626281c1b86ff
3
+ metadata.gz: e077d8eafaa333121b04b808c43d91a7e8e5a7704bfd33ed82be8f978d3748bf
4
+ data.tar.gz: 05a7e8ed6eca0572f930a678fc933175c07e6c96a261e27e4b5fa75ccb3f7130
5
5
  SHA512:
6
- metadata.gz: 3d2fd4b4c45ac7d182e76c3f32bc727554fb426198c18d6483d80f8eb954d6a2e233f26032a1b3cbddc1c412ec2b5cb927bcbd727f40b7c1134b7f12ab961485
7
- data.tar.gz: cacd448755258045d862c633bab834440f80f21c5a37f9d341241b464f8a8f10f7643ac82d8a68969251c647ce12af78bd799e7a251407095b058bea300f09d3
6
+ metadata.gz: 3b5b11770396e1fe729dffd41f33c0fb0328760ada247b749969083b74076207d36e0e3c805234a88169a30e71d1b419e92c01ba1e884022d8df259df4135112
7
+ data.tar.gz: 8647c6a0277f269b38ee43085db288c61d6f49d18d4d09df186aaa22214168dd2e8d9dc1e81e46197f9c274df6592abf4eac08d867e58d8c6468dd92ffbe8e32
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ Layout/EmptyLineAfterGuardClause:
7
7
  Layout/MultilineMethodCallIndentation:
8
8
  Enabled: false
9
9
  Metrics/AbcSize:
10
- Max: 60
10
+ Max: 65
11
11
  Metrics/BlockLength:
12
12
  Max: 30
13
13
  Metrics/MethodLength:
data/futex.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.rubygems_version = '2.3.3'
32
32
  s.required_ruby_version = '>=2.3'
33
33
  s.name = 'futex'
34
- s.version = '0.7.0'
34
+ s.version = '0.8.0'
35
35
  s.license = 'MIT'
36
36
  s.summary = 'File-based mutex'
37
37
  s.description = 'Ruby Gem for file-based locking'
data/lib/futex.rb CHANGED
@@ -54,8 +54,16 @@ require 'time'
54
54
  # License:: MIT
55
55
  class Futex
56
56
  # Exception that is raised when we can't lock because of some other
57
- # process that is holding the lock now.
58
- class CantLock < StandardError; end
57
+ # process that is holding the lock now. There is an encapsulated
58
+ # <tt>start</tt> attribute of type <tt>Time</tt>, which points to the time
59
+ # when we started to try to acquire lock.
60
+ class CantLock < StandardError
61
+ attr_reader :start
62
+ def initialize(msg, start)
63
+ @start = start
64
+ super(msg)
65
+ end
66
+ end
59
67
 
60
68
  # Creates a new instance of the class.
61
69
  def initialize(path, log: STDOUT, timeout: 16, sleep: 0.005,
@@ -100,9 +108,9 @@ class Futex
100
108
  Thread.current.thread_variable_set(:futex_cycle, cycle)
101
109
  Thread.current.thread_variable_set(:futex_time, Time.now - start)
102
110
  if Time.now - start > @timeout
103
- raise CantLock, "#{b} can't get #{prefix}exclusive access \
111
+ raise CantLock.new("#{b} can't get #{prefix}exclusive access \
104
112
  to the file #{@path} because of the lock at #{@lock}, after #{age(start)} \
105
- of waiting: #{IO.read(@lock)} (modified #{age(File.mtime(@lock))} ago)"
113
+ of waiting: #{IO.read(@lock)} (modified #{age(File.mtime(@lock))} ago)", start)
106
114
  end
107
115
  next unless (cycle % step).zero? && Time.now - start > @timeout / 2
108
116
  debug("#{b} still waiting for #{prefix}exclusive \
data/test/test_futex.rb CHANGED
@@ -89,6 +89,7 @@ class FutexTest < Minitest::Test
89
89
  end
90
90
  end
91
91
  assert(ex.message.include?('can\'t get exclusive access to the file'), ex)
92
+ assert(!ex.start.nil?)
92
93
  end
93
94
  end
94
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: futex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2018-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest