Class: Fluent::Counter::CleanupThread

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/counter/mutex_hash.rb

Constant Summary collapse

CLEANUP_INTERVAL =

15 min

60 * 15

Instance Method Summary collapse

Constructor Details

#initialize(store, mutex_hash, mutex) ⇒ CleanupThread

Returns a new instance of CleanupThread.



104
105
106
107
108
109
110
# File 'lib/fluent/counter/mutex_hash.rb', line 104

def initialize(store, mutex_hash, mutex)
  @store = store
  @mutex_hash = mutex_hash
  @mutex = mutex
  @thread = nil
  @running = false
end

Instance Method Details

#startObject



112
113
114
115
116
117
118
119
120
# File 'lib/fluent/counter/mutex_hash.rb', line 112

def start
  @running = true
  @thread = Thread.new do
    while @running
      sleep CLEANUP_INTERVAL
      run_once
    end
  end
end

#stopObject



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fluent/counter/mutex_hash.rb', line 122

def stop
  return unless @running
  @running = false
  begin
    # Avoid waiting CLEANUP_INTERVAL
    Timeout.timeout(1) do
      @thread.join
    end
  rescue Timeout::Error
    @thread.kill
  end
end