Class: LaunchDarkly::FileDataSourceImpl::FileDataSourcePoller

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/file_data_source.rb

Overview

Used internally by FileDataSource to track data file changes if the ‘listen’ gem is not available.

Instance Method Summary collapse

Constructor Details

#initialize(resolved_paths, interval, reloader, logger) ⇒ FileDataSourcePoller

Returns a new instance of FileDataSourcePoller.



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ldclient-rb/file_data_source.rb', line 272

def initialize(resolved_paths, interval, reloader, logger)
  @stopped = Concurrent::AtomicBoolean.new(false)
  get_file_times = Proc.new do
    ret = {}
    resolved_paths.each do |path|
      begin
        ret[path] = File.mtime(path)
      rescue Errno::ENOENT
        ret[path] = nil
      end
    end
    ret
  end
  last_times = get_file_times.call
  @thread = Thread.new do
    while true
      sleep interval
      break if @stopped.value
      begin
        new_times = get_file_times.call
        changed = false
        last_times.each do |path, old_time|
          new_time = new_times[path]
          if !new_time.nil? && new_time != old_time
            changed = true
            break
          end
        end
        reloader.call if changed
      rescue => exn
        Util.log_exception(logger, "Unexpected exception in FileDataSourcePoller", exn)
      end
    end
  end
end

Instance Method Details

#stopObject



308
309
310
311
# File 'lib/ldclient-rb/file_data_source.rb', line 308

def stop
  @stopped.make_true
  @thread.run  # wakes it up if it's sleeping
end