Class: Daemon::Utils::RedisWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/onapp/engine/utils/redis_watcher.rb

Instance Method Summary (collapse)

Constructor Details

- (RedisWatcher) initialize(redis)

Returns a new instance of RedisWatcher



8
9
10
11
12
# File 'lib/onapp/engine/utils/redis_watcher.rb', line 8

def initialize(redis)
  @redis = redis
  @on_redis_online = @on_redis_offline = proc{}
  @online = false
end

Instance Method Details

- (Object) on_redis_offline(&block)



18
19
20
# File 'lib/onapp/engine/utils/redis_watcher.rb', line 18

def on_redis_offline(&block)
  @on_redis_offline = block if block
end

- (Object) on_redis_online(&block)



14
15
16
# File 'lib/onapp/engine/utils/redis_watcher.rb', line 14

def on_redis_online(&block)
  @on_redis_online = block if block
end

- (Object) watch



22
23
24
25
26
27
28
29
30
31
# File 'lib/onapp/engine/utils/redis_watcher.rb', line 22

def watch
  @thread ||= begin
    Thread.new do
      Daemon::Utils::Retry.retry(Redis::BaseError, SystemCallError, on_error: proc { offline! }) do
        online! if @redis.ping
        @redis.blpop(SecureRandom.hex(10))
      end
    end
  end
end