25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/file_monitoring/file_monitoring.rb', line 25
def monitor_files
config_yml = YAML::load_file(@config_path)
conf_array = config_yml['paths']
pq = Containers::PriorityQueue.new
conf_array.each { |elem|
priority = (Time.now + elem['scan_period']).to_i
dir_stat = DirStat.new(elem['path'], elem['stable_state'])
dir_stat.set_event_queue(@event_queue) if @event_queue
Log.info [priority, elem, dir_stat]
pq.push([priority, elem, dir_stat], -priority)
}
log_path = Params['default_log_path']
if config_yml.key?('log_path')
log_path = File.expand_path(config_yml['log_path'])
end
Log.info 'Log path:' + log_path
FileUtils.mkdir_p(File.dirname(log_path))
log = File.open(log_path, 'w')
FileStat.set_log(log)
while true do
time, conf, dir_stat = pq.pop
time_span = time - Time.now.to_i
if (time_span > 0)
sleep(time_span)
end
dir_stat.monitor
priority = (Time.now + conf['scan_period']).to_i
pq.push([priority, conf, dir_stat], -priority)
end
log.close
end
|