file_monitoring 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ module FileMonitoring
18
18
  Params.path('default_monitoring_log_path', '~/.bbfs/log/file_monitoring.log',
19
19
  'Default path for file monitoring log file. ' \
20
20
  'This log containd track of changes found during monitoring')
21
- Params.complex('monitoring_paths', nil, 'Array of Hashes with 3 fields: ' \
21
+ Params.complex('monitoring_paths', [], 'Array of Hashes with 3 fields: ' \
22
22
  'path, scan_period and stable_state.')
23
23
 
24
24
  # @see FileMonitoring#monitor_files
@@ -9,6 +9,18 @@ module FileMonitoring
9
9
  # Manages file monitoring of number of file system locations
10
10
  class FileMonitoring
11
11
 
12
+ def initialize (dynamic_content_data)
13
+ @content_data_cache = Set.new
14
+ dynamic_content_data.each_instance(){
15
+ |checksum, size, content_modification_time,
16
+ instance_modification_time, server, file_path|
17
+ # save files to cache
18
+ Log.info("File in cache: #{file_path}")
19
+ @content_data_cache.add(file_path)
20
+ }
21
+ end
22
+
23
+
12
24
  # Set event queue used for communication between different proceses.
13
25
  # @param queue [Queue]
14
26
  def set_event_queue(queue)
@@ -28,14 +40,13 @@ module FileMonitoring
28
40
  # that provides path and file monitoring configuration data
29
41
  def monitor_files
30
42
  conf_array = Params['monitoring_paths']
31
-
32
43
  # Directories states stored in the priority queue,
33
44
  # where the key (priority) is a time when it should be checked next time.
34
45
  # Priority queue means that all entries arranged by key (time to check) in increasing order.
35
46
  pq = Containers::PriorityQueue.new
36
47
  conf_array.each { |elem|
37
48
  priority = (Time.now + elem['scan_period']).to_i
38
- dir_stat = DirStat.new(File.expand_path(elem['path']), elem['stable_state'])
49
+ dir_stat = DirStat.new(File.expand_path(elem['path']), elem['stable_state'], @content_data_cache, FileStatEnum::NON_EXISTING)
39
50
  dir_stat.set_event_queue(@event_queue) if @event_queue
40
51
  Log.debug1 "File monitoring started for: #{elem}"
41
52
  pq.push([priority, elem, dir_stat], -priority)
@@ -66,7 +77,6 @@ module FileMonitoring
66
77
  # pull entry that should be checked next,
67
78
  # according to it's scan_period
68
79
  time, conf, dir_stat = pq.pop
69
-
70
80
  # time remains to wait before directory should be checked
71
81
  time_span = time - Time.now.to_i
72
82
  if (time_span > 0)
@@ -1,3 +1,4 @@
1
+ require 'content_server/globals'
1
2
  require 'log'
2
3
  require 'params'
3
4
 
@@ -10,6 +11,8 @@ module FileMonitoring
10
11
  # * <tt>CHANGED</tt> - State was changed between two checks
11
12
  # * <tt>UNCHANGED</tt> - Opposite to CHANGED
12
13
  # * <tt>STABLE</tt> - Entity is in the UNCHANGED state for a defined (by user) number of iterations
14
+
15
+
13
16
  class FileStatEnum
14
17
  NON_EXISTING = "NON_EXISTING"
15
18
  NEW = "NEW"
@@ -31,25 +34,24 @@ module FileMonitoring
31
34
  #
32
35
  # * <tt>path</tt> - File location
33
36
  # * <tt>stable_state</tt> - Number of iterations to move unchanged file to stable state
34
- def initialize(path, stable_state = DEFAULT_STABLE_STATE)
37
+ def initialize(path, stable_state = DEFAULT_STABLE_STATE, content_data_cache, state)
35
38
  ObjectSpace.define_finalizer(self,
36
39
  self.class.method(:finalize).to_proc)
37
40
  if Params['enable_monitoring']
38
- Params['process_vars'].inc('obj add FileStat')
41
+ ::ContentServer::Globals.process_vars.inc('obj add FileStat')
39
42
  end
40
43
  @path ||= path
41
44
  @size = nil
42
45
  @creation_time = nil
43
46
  @modification_time = nil
44
47
  @cycles = 0 # number of iterations from the last file modification
45
- @state = FileStatEnum::NON_EXISTING
46
-
48
+ @state = state
47
49
  @stable_state = stable_state # number of iteration to move unchanged file to stable state
48
50
  end
49
51
 
50
52
  def self.finalize(id)
51
53
  if Params['enable_monitoring']
52
- Params['process_vars'].inc('obj rem FileStat')
54
+ ::ContentServer::Globals.process_vars.inc('obj rem FileStat')
53
55
  end
54
56
  end
55
57
 
@@ -121,7 +123,8 @@ module FileMonitoring
121
123
  end
122
124
  if (!@event_queue.nil?)
123
125
  Log.debug1 "Writing to event queue [#{self.state}, #{self.path}]"
124
- @event_queue.push([self.state, self.instance_of?(DirStat), self.path])
126
+ @event_queue.push([self.state, self.instance_of?(DirStat), self.path,
127
+ self.modification_time, self.size])
125
128
  end
126
129
  end
127
130
  end
@@ -144,23 +147,24 @@ module FileMonitoring
144
147
  #
145
148
  # * <tt>path</tt> - File location
146
149
  # * <tt>stable_state</tt> - Number of iterations to move unchanged directory to stable state
147
- def initialize(path, stable_state = DEFAULT_STABLE_STATE)
150
+ def initialize(path, stable_state = DEFAULT_STABLE_STATE, content_data_cache, state)
148
151
  ObjectSpace.define_finalizer(self,
149
152
  self.class.method(:finalize).to_proc)
150
153
  if Params['enable_monitoring']
151
- Params['process_vars'].inc('obj add DirStat')
154
+ ::ContentServer::Globals.process_vars.inc('obj add DirStat')
152
155
  end
153
156
  super
154
157
  @dirs = nil
155
158
  @files = nil
156
159
  @non_utf8_paths = {}
160
+ @content_data_cache = content_data_cache
157
161
  ObjectSpace.define_finalizer(self,
158
162
  self.class.method(:finalize).to_proc)
159
163
  end
160
164
 
161
165
  def self.finalize(id)
162
166
  if Params['enable_monitoring']
163
- Params['process_vars'].inc('obj rem DirStat')
167
+ ::ContentServer::Globals.process_vars.inc('obj rem DirStat')
164
168
  end
165
169
  end
166
170
 
@@ -289,7 +293,7 @@ module FileMonitoring
289
293
  # change state only for existing directories
290
294
  # newly added directories have to remain with NEW state
291
295
  was_changed = true
292
- ds = DirStat.new(file, self.stable_state)
296
+ ds = DirStat.new(file, self.stable_state, @content_data_cache, FileStatEnum::NON_EXISTING)
293
297
  ds.set_event_queue(@event_queue) unless @event_queue.nil?
294
298
  ds.monitor
295
299
  add_dir(ds)
@@ -299,7 +303,13 @@ module FileMonitoring
299
303
  # change state only for existing directories
300
304
  # newly added directories have to remain with NEW state
301
305
  was_changed = true
302
- fs = FileStat.new(file, self.stable_state)
306
+ # check if file exist in content data cache - set state to STABLE
307
+ file_state = FileStatEnum::NON_EXISTING
308
+ if !@content_data_cache.nil? && @content_data_cache.include?(file)
309
+ file_state = FileStatEnum::STABLE
310
+ end
311
+ fs = FileStat.new(file, self.stable_state, @content_data_cache, file_state)
312
+
303
313
  fs.set_event_queue(@event_queue) unless @event_queue.nil?
304
314
  fs.monitor
305
315
  add_file(fs)
@@ -1,3 +1,3 @@
1
1
  module FileMonitoring
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_monitoring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: