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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/unique_thread.rb +12 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da0b2a8f7bf6e6be0baa044b53d85c1e5903a3c0
4
- data.tar.gz: a9a6f8b6f7097b0abef203c016dd3051a1e2cdb9
3
+ metadata.gz: a577e3fc0c14fba6313822f463fc97d7d19f0408
4
+ data.tar.gz: 349372ae107ba9cbd955242240be91c89e389d4e
5
5
  SHA512:
6
- metadata.gz: 7e662fe91f55a1a70c68e71a70f12cf83dcb9191f47bd1df8ad52bbe155b222af03d20f37d70350b5667645d2cc8b4885c8cd2042bb522aba86c7f807fd4fbdd
7
- data.tar.gz: e79b9b0a27c659651ef8c41fc8a8e4394de2a88977a4a76e3125daa1bddf7915cf416e886d494eaca754e17c6e1592adfc88055f061c31ac2134ec31ac9ce0b2
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: Logger.new(STDOUT), redis: Redis.new)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unique_thread
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Seror