Method: PhusionPassenger::Standalone::AppFinder#monitor

Defined in:
lib/phusion_passenger/standalone/app_finder.rb

#monitor(termination_pipe) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/phusion_passenger/standalone/app_finder.rb', line 77

def monitor(termination_pipe)
	raise "You must call #scan first" if !@apps
	
	watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
	if wait_on_io(termination_pipe, 3)
		return
	end
	
	while true
		changed = watcher.wait_for_change
		watcher.close
		if changed
			old_apps = @apps
			# The change could be caused by a write to some passenger.conf file.
			# Wait for a short period so that the write has a chance to finish.
			if wait_on_io(termination_pipe, 0.25)
				return
			end
			
			new_apps = scan
			watcher = PhusionPassenger::Utils::FileSystemWatcher.new(@watchlist, termination_pipe)
			if old_apps != new_apps
				yield(new_apps)
			end
			
			# Don't process change events again for a short while,
			# but do detect changes while waiting.
			if wait_on_io(termination_pipe, 3)
				return
			end
		else
			return
		end
	end
ensure
	watcher.close if watcher
end