Module: RedisRing::BackgroundThread

Included in:
ProcessManager, WebInterfaceRunner, ZookeeperObserver
Defined in:
lib/redis_ring/background_thread.rb

Instance Method Summary collapse

Instance Method Details

#after_haltObject



8
9
# File 'lib/redis_ring/background_thread.rb', line 8

def after_halt
end

#before_runObject



5
6
# File 'lib/redis_ring/background_thread.rb', line 5

def before_run
end

#continue_running?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/redis_ring/background_thread.rb', line 35

def continue_running?
  @continue_running
end

#do_workObject



11
12
# File 'lib/redis_ring/background_thread.rb', line 11

def do_work
end

#haltObject



39
40
41
# File 'lib/redis_ring/background_thread.rb', line 39

def halt
  @continue_running = false
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/redis_ring/background_thread.rb', line 14

def run
  before_run

  @continue_running = true

  return Thread.new do
    begin
      while continue_running?
        do_work
      end
      after_halt
    rescue SystemExit
      raise
    rescue => e
      puts "Error caught in #{self.class.name}:"
      puts e
      puts e.backtrace.join("\n")
    end
  end
end