Class: NetworkResiliency::Syncer

Inherits:
Thread
  • Object
show all
Defined in:
lib/network_resiliency/syncer.rb

Constant Summary collapse

LOCK =
Mutex.new
SLEEP_DURATION =
10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSyncer

Returns a new instance of Syncer.



35
36
37
# File 'lib/network_resiliency/syncer.rb', line 35

def initialize
  super { sync }
end

Class Method Details

.startObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/network_resiliency/syncer.rb', line 7

def start
  return unless NetworkResiliency.redis

  LOCK.synchronize do
    unless @instance&.alive?
      @instance = new
      NetworkResiliency.statsd&.increment("network_resiliency.syncer.start")
    end

    @instance
  end
end

.stopObject



20
21
22
23
24
25
26
27
28
# File 'lib/network_resiliency/syncer.rb', line 20

def stop
  LOCK.synchronize do
    if @instance
      @instance.shutdown
      @instance.join
      @instance = nil
    end
  end
end

.syncing?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/network_resiliency/syncer.rb', line 30

def syncing?
  !!@instance&.alive?
end

Instance Method Details

#shutdownObject



39
40
41
42
43
44
# File 'lib/network_resiliency/syncer.rb', line 39

def shutdown
  @shutdown = true

  # prevent needless delay
  self.raise Interrupt if status == "sleep"
end