unique_thread 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unique_thread.rb +12 -1
- 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: a577e3fc0c14fba6313822f463fc97d7d19f0408
|
4
|
+
data.tar.gz: 349372ae107ba9cbd955242240be91c89e389d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7634616c9aa414db034a343ac7b55fe890bb82548541ed6004890bbcb5ba5999b33332f4cfb29f377e2e8f025f6bdef757aa5ad26afec35af7be2d8c77bc7fe5
|
7
|
+
data.tar.gz: 32d117b11d1ba44b76d0e7e89b7f39733501a17604fba3dcf37a12e9aac03a0c9a48b92dcdf065023570a6e519b13176b5b561a9fe30427d0170d6664ce322cf
|
data/lib/unique_thread.rb
CHANGED
@@ -8,7 +8,7 @@ require_relative 'unique_thread/locksmith'
|
|
8
8
|
class UniqueThread
|
9
9
|
attr_reader :logger, :stopwatch, :locksmith
|
10
10
|
|
11
|
-
def initialize(name, downtime: 30, logger:
|
11
|
+
def initialize(name, downtime: 30, logger: default_logger, redis: Redis.new)
|
12
12
|
@logger = logger
|
13
13
|
@stopwatch = Stopwatch.new(downtime: downtime)
|
14
14
|
@locksmith = Locksmith.new(name: name, stopwatch: stopwatch, redis: redis, logger: logger)
|
@@ -30,6 +30,17 @@ class UniqueThread
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
def self.default_logger
|
34
|
+
case
|
35
|
+
when defined?(Rails) && defined?(Rails::Console)
|
36
|
+
Logger.new('/dev/null')
|
37
|
+
when defined?(Rails)
|
38
|
+
Rails.logger
|
39
|
+
else
|
40
|
+
Logger.new(STDOUT)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
33
44
|
def safe_infinite_loop
|
34
45
|
Thread.new do
|
35
46
|
begin
|