Class: LaunchDarkly::Impl::Integrations::FileDataSourceImpl::FileDataSourcePoller Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Integrations::FileDataSourceImpl::FileDataSourcePoller
- Defined in:
- lib/ldclient-rb/impl/integrations/file_data_source.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Used internally by FileDataSource to track data file changes if the 'listen' gem is not available.
Instance Method Summary collapse
-
#initialize(resolved_paths, interval, reloader, logger) ⇒ FileDataSourcePoller
constructor
private
A new instance of FileDataSourcePoller.
- #stop ⇒ Object private
Constructor Details
#initialize(resolved_paths, interval, reloader, logger) ⇒ FileDataSourcePoller
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of FileDataSourcePoller.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 185 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 Impl::Util.log_exception(logger, "Unexpected exception in FileDataSourcePoller", exn) end end end @thread.name = "LD/FileDataSource" end |
Instance Method Details
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
222 223 224 225 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source.rb', line 222 def stop @stopped.make_true @thread.run # wakes it up if it's sleeping end |