Class: ProcessSettings::FileMonitor
- Inherits:
-
AbstractMonitor
- Object
- AbstractMonitor
- ProcessSettings::FileMonitor
- Defined in:
- lib/process_settings/file_monitor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#untargeted_settings ⇒ Object
readonly
Returns the value of attribute untargeted_settings.
Attributes inherited from AbstractMonitor
#full_context_cache, #logger, #min_polling_seconds, #static_context, #statically_targeted_settings
Instance Method Summary collapse
-
#initialize(file_path, logger:, environment: nil) ⇒ FileMonitor
constructor
A new instance of FileMonitor.
- #listen_thread_running? ⇒ Boolean
- #restart_after_fork ⇒ Object
- #start ⇒ Object
- #start_watchdog_thread(file_path) ⇒ Object
- #stop_watchdog_thread ⇒ Object
Methods inherited from AbstractMonitor
#[], #cancel_when_updated, ensure_no_symbols, #full_context_from_cache, #on_change, #targeted_value, #when_updated
Constructor Details
#initialize(file_path, logger:, environment: nil) ⇒ FileMonitor
Returns a new instance of FileMonitor.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/process_settings/file_monitor.rb', line 17 def initialize(file_path, logger:, environment: nil) super(logger: logger) @file_path = File.(file_path) @last_statically_targetted_settings = nil @untargeted_settings = nil @last_untargetted_settings = nil start_internal(enable_listen_thread?(environment)) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
15 16 17 |
# File 'lib/process_settings/file_monitor.rb', line 15 def file_path @file_path end |
#untargeted_settings ⇒ Object (readonly)
Returns the value of attribute untargeted_settings.
15 16 17 |
# File 'lib/process_settings/file_monitor.rb', line 15 def untargeted_settings @untargeted_settings end |
Instance Method Details
#listen_thread_running? ⇒ Boolean
55 56 57 |
# File 'lib/process_settings/file_monitor.rb', line 55 def listen_thread_running? !@listener.nil? end |
#restart_after_fork ⇒ Object
51 52 53 |
# File 'lib/process_settings/file_monitor.rb', line 51 def restart_after_fork start_internal(enable_listen_thread?) end |
#start ⇒ Object
46 47 48 |
# File 'lib/process_settings/file_monitor.rb', line 46 def start start_internal(enable_listen_thread?) end |
#start_watchdog_thread(file_path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/process_settings/file_monitor.rb', line 28 def start_watchdog_thread(file_path) @watchdog_thread and raise ArgumentError, "watchdog thread already running!" @watchdog_thread = Thread.new do watchdog = Watchdog.new(file_path) loop do sleep(1.minute) watchdog.check rescue => ex logger.error("ProcessSettings::Watchdog thread: #{ex.class.name}: #{ex.}") end end end |
#stop_watchdog_thread ⇒ Object
41 42 43 44 |
# File 'lib/process_settings/file_monitor.rb', line 41 def stop_watchdog_thread @watchdog_thread&.kill @watchdog_thread = nil end |