Class: BBFS::FileMonitoring::FileMonitoring

Inherits:
Object
  • Object
show all
Defined in:
lib/file_monitoring/file_monitoring.rb

Instance Method Summary collapse

Instance Method Details

#monitor_filesObject



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
    #Log.info 'time:' + time.to_s()
    #Log.info 'now:' + Time.now.to_i.to_s()
    #Log.info conf

    time_span = time - Time.now.to_i
    if (time_span > 0)
      sleep(time_span)
    end
    dir_stat.monitor

    #Log.info conf['path']
    #Log.info conf['scan_period']
    priority = (Time.now + conf['scan_period']).to_i
    pq.push([priority, conf, dir_stat], -priority)
  end

  log.close
end

#set_config_path(config_path) ⇒ Object



17
18
19
# File 'lib/file_monitoring/file_monitoring.rb', line 17

def set_config_path(config_path)
  @config_path = config_path
end

#set_event_queue(queue) ⇒ Object



21
22
23
# File 'lib/file_monitoring/file_monitoring.rb', line 21

def set_event_queue(queue)
  @event_queue = queue
end