Class: UniqueThread
- Inherits:
-
Object
show all
- Defined in:
- lib/unique_thread.rb,
lib/unique_thread/locksmith.rb,
lib/unique_thread/stopwatch.rb
Defined Under Namespace
Classes: HeldLock, Lock, Locksmith, Stopwatch
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, downtime: 30) ⇒ UniqueThread
Returns a new instance of UniqueThread.
56
57
58
59
|
# File 'lib/unique_thread.rb', line 56
def initialize(name, downtime: 30)
@stopwatch = Stopwatch.new(downtime: downtime)
@locksmith = Locksmith.new(name: name, stopwatch: stopwatch)
end
|
Class Attribute Details
.error_handlers ⇒ Object
20
21
22
|
# File 'lib/unique_thread.rb', line 20
def error_handlers
@error_handlers ||= []
end
|
.logger ⇒ Object
12
13
14
|
# File 'lib/unique_thread.rb', line 12
def logger
@logger ||= default_logger
end
|
.redis ⇒ Object
16
17
18
|
# File 'lib/unique_thread.rb', line 16
def redis
@redis ||= Redis.new
end
|
Instance Attribute Details
#locksmith ⇒ Object
Returns the value of attribute locksmith.
54
55
56
|
# File 'lib/unique_thread.rb', line 54
def locksmith
@locksmith
end
|
#stopwatch ⇒ Object
Returns the value of attribute stopwatch.
54
55
56
|
# File 'lib/unique_thread.rb', line 54
def stopwatch
@stopwatch
end
|
Class Method Details
.safe_thread ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/unique_thread.rb', line 24
def safe_thread
Thread.new do
begin
yield
rescue StandardError => error
report_error(error)
retry
end
end
end
|
Instance Method Details
#run(&block) ⇒ Object
61
62
63
64
65
|
# File 'lib/unique_thread.rb', line 61
def run(&block)
self.class.safe_thread do
loop { try_being_the_unique_thread(&block) }
end
end
|