Class: LaunchDarkly::Impl::Integrations::FileDataSourcePollerV2 Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Integrations::FileDataSourcePollerV2
- Defined in:
- lib/ldclient-rb/impl/integrations/file_data_source_v2.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 FileDataSourceV2 to track data file changes if the 'listen' gem is not available.
Instance Method Summary collapse
-
#initialize(resolved_paths, interval, on_change_callback, logger) ⇒ FileDataSourcePollerV2
constructor
private
Initialize the file data poller.
- #stop ⇒ Object private
Constructor Details
#initialize(resolved_paths, interval, on_change_callback, logger) ⇒ FileDataSourcePollerV2
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.
Initialize the file data poller.
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source_v2.rb', line 410 def initialize(resolved_paths, interval, on_change_callback, logger) @stopped = Concurrent::AtomicBoolean.new(false) @on_change = on_change_callback @logger = logger get_file_times = proc 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 loop do 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 last_times = new_times @on_change.call if changed rescue => e Impl::Util.log_exception(@logger, "Unexpected exception in FileDataSourcePollerV2", e) end end end @thread.name = "LD/FileDataSourceV2" 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.
453 454 455 456 |
# File 'lib/ldclient-rb/impl/integrations/file_data_source_v2.rb', line 453 def stop @stopped.make_true @thread.run # wakes it up if it's sleeping end |