Class: LaunchDarkly::Impl::Integrations::FileDataSourceImpl::FileDataSourcePoller

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

Overview

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

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FileDataSourcePoller.

Since:

  • 5.5.0



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 168

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
        LaunchDarkly::Util.log_exception(logger, "Unexpected exception in FileDataSourcePoller", exn)
      end
    end
  end
end

Instance Method Details

#stopObject

Since:

  • 5.5.0



204
205
206
207
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 204

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