Class: LaunchDarkly::Impl::FileData::Poller Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::FileData::Poller
- Defined in:
- lib/ldclient-rb/impl/file_data/poller.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.
Detects changes to a set of files by examining them on a fixed interval. Use it where file system change notifications are not available or not reliable. A change to the modification time or the size of any file invokes the callback. A file that appears or disappears is also a change. A file that cannot be examined counts as absent.
The poller samples the files once per interval and compares only modification time and size. A rewrite that keeps both values is not detected.
Detection is generous. The callback can run for a change that does not alter the effective data. Feed it into a Reloader, whose debouncing and skip-unchanged handling absorb the excess.
Defined Under Namespace
Classes: FileState
Class Method Summary collapse
-
.observe(path) ⇒ FileState
private
Examines one file.
-
.observe_all(paths) ⇒ Array<FileState>
private
Examines every file and returns the observed states, in path order.
Instance Method Summary collapse
-
#initialize(paths, interval, on_change, logger) ⇒ Poller
constructor
private
Creates and starts a poller.
-
#stop ⇒ Object
private
Stops the poller and waits for the worker thread to finish.
Constructor Details
#initialize(paths, interval, on_change, logger) ⇒ Poller
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.
Creates and starts a poller. It examines the files once before it returns, so only later changes invoke the callback. Call #stop to stop it.
39 40 41 42 43 44 45 |
# File 'lib/ldclient-rb/impl/file_data/poller.rb', line 39 def initialize(paths, interval, on_change, logger) @paths = paths @on_change = on_change @last = Poller.observe_all(paths) @task = RepeatingTask.new(interval, interval, method(:examine), logger, "LD/FileDataPoller") @task.start end |
Class Method Details
.observe(path) ⇒ FileState
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.
Examines one file. The state is that of the file a symbolic link leads to.
71 72 73 74 75 76 |
# File 'lib/ldclient-rb/impl/file_data/poller.rb', line 71 def self.observe(path) stat = File.stat(path) FileState.new(true, stat.mtime, stat.size) rescue SystemCallError ABSENT end |
.observe_all(paths) ⇒ Array<FileState>
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.
Examines every file and returns the observed states, in path order.
61 62 63 |
# File 'lib/ldclient-rb/impl/file_data/poller.rb', line 61 def self.observe_all(paths) paths.map { |path| observe(path) } 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.
Stops the poller and waits for the worker thread to finish. A callback that is already running completes first.
51 52 53 |
# File 'lib/ldclient-rb/impl/file_data/poller.rb', line 51 def stop @task.stop end |