logstash-input-file 4.4.6 → 4.4.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabfa7af5953763874689d9cba6691d9184de195e33dbf40425021653e8f3548
4
- data.tar.gz: cdca8f6300254f1d32b327194ed5977f85bb47b6912a27170d4bbacae2d6bad8
3
+ metadata.gz: 1cf44bedf030b1d832d6fe95700388e94ba99e810514ec2490d9c458b4ba7ad2
4
+ data.tar.gz: 62034dc97d1ce6b381a113e09f466c64fd14bcea1f3c78d4d6dbaede58fe11e7
5
5
  SHA512:
6
- metadata.gz: bbbe5f2f43e7ef106a67bc63ebacb71d1312574dbfac8f4566ab4fef400ad751d6be0e258d8eac2358116c6e90584ca0664b2a5d44e0d853d84ff2703f148904
7
- data.tar.gz: 4a7f8f7bedc904dc059ffe8acac14da3ff63663b6a4a5e748c8750952e85a5f15dc0024d696c3de5611fd40408e8f7be7d30c8cb0c5ca9ac2f436aab55d8bb4d
6
+ metadata.gz: 47422dd58db7bbf779a9fd8c2416855d4e306ffa5a1e5e38d73d9a7a8ed2dbc4e16a3ba5150e642ece8c88fb1579c72845866fb23232e46f4a150a33e7188801
7
+ data.tar.gz: 6b5746d4ffc9812095b4fa7cffb2cb0d8e375c02ddeabc917ac489ddb7db1299a660b3d7dc691e5b1ee25678021ce0d798a63e6a70960bc0ac91624dc05503e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 4.4.8
2
+ - Fix create + rename rotation not being detected on Windows, which caused new content to be lost and old content to be re-read [#340](https://github.com/logstash-plugins/logstash-input-file/pull/340)
3
+ - Read content appended to a file before it was rotated instead of dropping it [#340](https://github.com/logstash-plugins/logstash-input-file/pull/340)
4
+ - Stop joining a partial line to the next line after a file is truncated [#340](https://github.com/logstash-plugins/logstash-input-file/pull/340)
5
+
6
+ ## 4.4.7
7
+ - Re-packaging the plugin [#331](https://github.com/logstash-plugins/logstash-input-file/pull/331)
8
+
1
9
  ## 4.4.6
2
10
  - Change read mode to immediately stop consuming buffered lines when shutdown is requested [#322](https://github.com/logstash-plugins/logstash-input-file/pull/322)
3
11
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
- Travis Build
3
- [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-input-file.svg)](https://travis-ci.com/logstash-plugins/logstash-input-file)
2
+ Unit Tests
3
+ [![Unit Tests](https://github.com/logstash-plugins/logstash-input-file/actions/workflows/unit-tests.yml/badge.svg?branch=main)](https://github.com/logstash-plugins/logstash-input-file/actions/workflows/unit-tests.yml)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
@@ -1,20 +1,35 @@
1
1
  # encoding: utf-8
2
+ require "logstash/util/loggable"
2
3
 
3
4
  module FileWatch module Stat
4
5
  class WindowsPath
6
+ include LogStash::Util::Loggable
5
7
 
6
8
  attr_reader :inode, :modified_at, :size, :inode_struct
7
9
 
8
10
  def initialize(source)
9
11
  @source = source # Pathname
10
- @inode = Winhelper.identifier_from_path(@source.to_path)
11
- # in windows the dev hi and low are in the identifier
12
- @inode_struct = InodeStruct.new(@inode, 0, 0)
12
+ @inode = nil
13
13
  restat
14
14
  end
15
15
 
16
16
  def restat
17
17
  stat = @source.stat
18
+ identifier = Winhelper.identifier_from_path(@source.to_path)
19
+ if @inode.nil?
20
+ if identifier == 'unknown'
21
+ logger.debug("restat: file identifier lookup failed, rotation will not be detected for this file", :path => @source.to_path)
22
+ end
23
+ set_identifier(identifier)
24
+ elsif @inode == 'unknown'
25
+ # stays unknown
26
+ elsif identifier == 'unknown'
27
+ logger.debug("restat: file identifier lookup failed, keeping previous stat", :path => @source.to_path, :identifier => @inode)
28
+ return
29
+ elsif identifier != @inode
30
+ logger.debug("restat: file identifier changed", :path => @source.to_path, :old_identifier => @inode, :new_identifier => identifier)
31
+ set_identifier(identifier)
32
+ end
18
33
  @modified_at = stat.mtime.to_f
19
34
  @size = stat.size
20
35
  end
@@ -26,5 +41,13 @@ module FileWatch module Stat
26
41
  def inspect
27
42
  "<#{self.class.name} size=#{@size}, modified_at=#{@modified_at}, inode=#{@inode}, inode_struct=#{@inode_struct}>"
28
43
  end
44
+
45
+ private
46
+
47
+ def set_identifier(identifier)
48
+ @inode = identifier
49
+ # in windows the dev hi and low are in the identifier
50
+ @inode_struct = InodeStruct.new(@inode, 0, 0)
51
+ end
29
52
  end
30
53
  end end
@@ -4,6 +4,10 @@ module FileWatch module TailMode module Handlers
4
4
  class Shrink < Base
5
5
  def handle_specifically(watched_file)
6
6
  add_or_update_sincedb_collection(watched_file)
7
+ discarded = watched_file.reset_buffer
8
+ unless discarded.nil? || discarded.empty?
9
+ logger.debug("shrink: discarding partial line buffered before the file shrank", :path => watched_file.path, :bytes => discarded.bytesize)
10
+ end
7
11
  watched_file.file_seek(watched_file.bytes_read)
8
12
  loop do
9
13
  break if quit?
@@ -141,6 +141,7 @@ module FileWatch module TailMode
141
141
  logger.trace(__method__.to_s)
142
142
  watched_files.each do |watched_file|
143
143
  next unless watched_file.rotation_in_progress?
144
+ watched_file.refresh_size_from_open_file
144
145
  if !watched_file.all_read?
145
146
  if watched_file.file_open?
146
147
  # rotated file but original opened file is not fully read
@@ -233,8 +233,14 @@ module FileWatch
233
233
  !@file.nil? && !@file.closed?
234
234
  end
235
235
 
236
+ def refresh_size_from_open_file
237
+ return unless file_open?
238
+ @size = @file.sysseek(0, IO::SEEK_END)
239
+ update_bytes_unread
240
+ end
241
+
236
242
  def reset_buffer
237
- @buffer.flush
243
+ @buffer.flush unless @buffer.nil?
238
244
  end
239
245
 
240
246
  def read_extract_lines(amount)
Binary file
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-input-file'
4
- s.version = '4.4.6'
4
+ s.version = ::File.read('version').split("\n").first
5
5
  s.licenses = ['Apache-2.0']
6
6
  s.summary = "Streams events from files"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "JAR_VERSION", "docs/**/*"]
14
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "version", "JAR_VERSION", "docs/**/*"]
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -5,13 +5,13 @@ describe FileWatch::BufferedTokenizer do
5
5
 
6
6
  context "when using the default delimiter" do
7
7
  it "splits the lines correctly" do
8
- expect(subject.extract("hello\nworld\n")).to eq ["hello", "world"]
8
+ expect(subject.extract("hello\nworld\n").to_a).to eq ["hello", "world"]
9
9
  end
10
10
 
11
11
  it "holds partial lines back until a token is found" do
12
12
  buffer = described_class.new
13
- expect(buffer.extract("hello\nwor")).to eq ["hello"]
14
- expect(buffer.extract("ld\n")).to eq ["world"]
13
+ expect(buffer.extract("hello\nwor").to_a).to eq ["hello"]
14
+ expect(buffer.extract("ld\n").to_a).to eq ["world"]
15
15
  end
16
16
  end
17
17
 
@@ -19,7 +19,7 @@ describe FileWatch::BufferedTokenizer do
19
19
  subject { FileWatch::BufferedTokenizer.new("\r\n") }
20
20
 
21
21
  it "splits the lines correctly" do
22
- expect(subject.extract("hello\r\nworld\r\n")).to eq ["hello", "world"]
22
+ expect(subject.extract("hello\r\nworld\r\n").to_a).to eq ["hello", "world"]
23
23
  end
24
24
  end
25
25
  end
@@ -48,7 +48,7 @@ module FileWatch
48
48
  reading.watch_this(watch_dir)
49
49
  end
50
50
  .then("wait") do
51
- wait(2).for{listener1.calls.last}.to eq(:delete)
51
+ wait(2).for{listener1.calls_history.last}.to eq(:delete)
52
52
  end
53
53
  .then("quit") do
54
54
  reading.quit
@@ -58,7 +58,7 @@ module FileWatch
58
58
  actions.activate_quietly
59
59
  reading.subscribe(observer)
60
60
  actions.assert_no_errors
61
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
61
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
62
62
  expect(listener1.lines).to eq(["line1", "line2"])
63
63
  end
64
64
  end
@@ -73,7 +73,7 @@ module FileWatch
73
73
  reading.watch_this(watch_dir)
74
74
  end
75
75
  .then("wait") do
76
- wait(2).for{listener1.calls.last}.to eq(:delete)
76
+ wait(2).for{listener1.calls_history.last}.to eq(:delete)
77
77
  end
78
78
  .then("quit") do
79
79
  reading.quit
@@ -83,7 +83,7 @@ module FileWatch
83
83
  actions.activate_quietly
84
84
  reading.subscribe(observer)
85
85
  actions.assert_no_errors
86
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
86
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
87
87
  expect(listener1.lines).to eq(["line1", "line2"])
88
88
  end
89
89
  end
@@ -104,7 +104,7 @@ module FileWatch
104
104
  reading.watch_this(watch_dir)
105
105
  end
106
106
  .then("wait") do
107
- wait(2).for{listener1.calls.last == :delete && listener2.calls.last == :delete}.to eq(true)
107
+ wait(2).for{listener1.calls_history.last == :delete && listener2.calls_history.last == :delete}.to eq(true)
108
108
  end
109
109
  .then("quit") do
110
110
  reading.quit
@@ -114,8 +114,8 @@ module FileWatch
114
114
  actions.activate_quietly
115
115
  reading.subscribe(observer)
116
116
  actions.assert_no_errors
117
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
118
- expect(listener2.calls).to eq([:open, :accept, :accept, :eof, :delete])
117
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
118
+ expect(listener2.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
119
119
  expect(lines).to eq(%w(string1 stringA string2 stringB))
120
120
  end
121
121
  end
@@ -130,7 +130,7 @@ module FileWatch
130
130
  reading.watch_this(watch_dir)
131
131
  end
132
132
  .then("wait") do
133
- wait(2).for{listener1.calls.last}.to eq(:delete)
133
+ wait(2).for{listener1.calls_history.last}.to eq(:delete)
134
134
  end
135
135
  .then("quit") do
136
136
  reading.quit
@@ -140,7 +140,7 @@ module FileWatch
140
140
  actions.activate_quietly
141
141
  reading.subscribe(observer)
142
142
  actions.assert_no_errors
143
- expect(listener1.calls).to eq([:open, :accept, :eof, :delete])
143
+ expect(listener1.calls_history).to eq([:open, :accept, :eof, :delete])
144
144
  expect(listener1.lines).to eq(["line1\nline2"])
145
145
  sincedb_record_fields = File.read(sincedb_path).split(" ")
146
146
  position_field_index = 3
@@ -171,13 +171,13 @@ module FileWatch
171
171
  reading.watch_this(watch_dir)
172
172
  end
173
173
  .then("wait12") do
174
- wait(2).for { listener1.calls.last == :delete && listener2.calls.last == :delete }.to eq(true)
174
+ wait(2).for { listener1.calls_history.last == :delete && listener2.calls_history.last == :delete }.to eq(true)
175
175
  end
176
176
  .then_after(2, "create3") do
177
177
  File.open(file_path3, "w") { |file| file.write("string31\nstring32") }
178
178
  end
179
179
  .then("wait3") do
180
- wait(2).for { listener3.calls.last == :delete }.to eq(true)
180
+ wait(2).for { listener3.calls_history.last == :delete }.to eq(true)
181
181
  end
182
182
  .then("quit") do
183
183
  reading.quit
@@ -233,7 +233,7 @@ module FileWatch
233
233
  File.open(file_path3, "w") { |file| file.write("line1\nline2\n") }
234
234
  reading.watch_this(watch_dir)
235
235
  reading.subscribe(observer)
236
- expect(listener3.calls).to eq([:open, :accept, :accept, :eof, :delete, :reading_completed])
236
+ expect(listener3.calls_history).to eq([:open, :accept, :accept, :eof, :delete, :reading_completed])
237
237
  end
238
238
 
239
239
  it "sincedb works correctly" do
@@ -251,8 +251,8 @@ module FileWatch
251
251
  reading.subscribe(observer)
252
252
  File.open(file_path6, "w") { |file| file.write("foob\nbar\n") }
253
253
  expect(listener3.lines).to eq(["line1", "line2"])
254
- expect(listener3.calls).to eq([:open, :accept, :accept, :eof, :delete, :reading_completed])
255
- expect(listener6.calls).to eq([])
254
+ expect(listener3.calls_history).to eq([:open, :accept, :accept, :eof, :delete, :reading_completed])
255
+ expect(listener6.calls_history).to eq([])
256
256
  end
257
257
 
258
258
  end
@@ -264,7 +264,7 @@ module FileWatch
264
264
  reading.watch_this(watch_dir)
265
265
  end
266
266
  .then("wait") do
267
- wait(1).for{listener1.calls.last}.to eq(:delete)
267
+ wait(1).for{listener1.calls_history.last}.to eq(:delete)
268
268
  end
269
269
  .then("quit") do
270
270
  reading.quit
@@ -279,7 +279,7 @@ module FileWatch
279
279
  actions.activate_quietly
280
280
  reading.subscribe(observer)
281
281
  actions.assert_no_errors
282
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
282
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
283
283
  expect(listener1.lines.size).to eq(2)
284
284
  end
285
285
  end
@@ -293,7 +293,7 @@ module FileWatch
293
293
  actions.activate_quietly
294
294
  reading.subscribe(observer)
295
295
  actions.assert_no_errors
296
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
296
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
297
297
  expect(listener1.lines.size).to eq(2)
298
298
  end
299
299
  end
@@ -307,7 +307,7 @@ module FileWatch
307
307
  actions.activate_quietly
308
308
  reading.subscribe(observer)
309
309
  actions.assert_no_errors
310
- expect(listener1.calls).to eq([:open, :accept, :accept, :eof, :delete])
310
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :eof, :delete])
311
311
  expect(listener1.lines.size).to eq(2)
312
312
  end
313
313
  end
@@ -22,7 +22,7 @@ require 'filewatch/observing_tail'
22
22
  # exist, then they are renamed to app.log.2, app.log.3 etc. respectively.
23
23
 
24
24
  module FileWatch
25
- describe Watch, :unix => true do
25
+ describe Watch do
26
26
  let(:directory) { Pathname.new(Stud::Temporary.directory) }
27
27
  let(:file1_path) { file_path.to_path }
28
28
  let(:max) { 4095 }
@@ -74,7 +74,7 @@ module FileWatch
74
74
  end
75
75
  .then("wait for expectation") do
76
76
  sleep(0.25) # if ENV['CI']
77
- wait(2).for { listener1.calls }.to eq([:open, :accept, :accept, :accept])
77
+ wait(2).for { listener1.calls_history }.to eq([:open, :accept, :accept, :accept])
78
78
  end
79
79
  .then("quit") do
80
80
  tailing.quit
@@ -93,7 +93,7 @@ module FileWatch
93
93
  end
94
94
  end
95
95
 
96
- context "create + rename rotation: a multiple file rename cascade" do
96
+ context "create + rename rotation: a multiple file rename cascade", :unix => true do
97
97
  let(:watch_dir) { directory.join("*B.log") }
98
98
  let(:file_path) { directory.join("1B.log") }
99
99
  subject { described_class.new(conf) }
@@ -135,7 +135,7 @@ module FileWatch
135
135
  end
136
136
  end
137
137
 
138
- context "create + rename rotation: a two file rename cascade in slow motion" do
138
+ context "create + rename rotation: a two file rename cascade in slow motion", :unix => true do
139
139
  let(:watch_dir) { directory.join("*C.log") }
140
140
  let(:file_path) { directory.join("1C.log") }
141
141
  let(:stat_interval) { 0.01 }
@@ -179,7 +179,7 @@ module FileWatch
179
179
  end
180
180
  end
181
181
 
182
- context "create + rename rotation: a two file rename cascade in normal speed" do
182
+ context "create + rename rotation: a two file rename cascade in normal speed", :unix => true do
183
183
  let(:watch_dir) { directory.join("*D.log") }
184
184
  let(:file_path) { directory.join("1D.log") }
185
185
  subject { described_class.new(conf) }
@@ -255,11 +255,48 @@ module FileWatch
255
255
  actions.assert_no_errors
256
256
  expected_calls = ([:accept] * 66).unshift(:open)
257
257
  expect(listener1.lines.uniq).to eq([line1])
258
- expect(listener1.calls).to eq(expected_calls)
258
+ expect(listener1.calls_history).to eq(expected_calls)
259
259
  expect(sincedb_path.readlines.size).to eq(2)
260
260
  end
261
261
  end
262
262
 
263
+ context "create + rename rotation: when content is appended to the open file after its last stat and it is then renamed outside glob" do
264
+ let(:stat_interval) { 1 }
265
+ let(:discover_interval) { 1 }
266
+ let(:watch_dir) { directory.join("*G.log") }
267
+ let(:file_path) { directory.join("1G.log") }
268
+ subject { described_class.new(conf) }
269
+ let(:listener1) { observer.listener_for(file1_path) }
270
+ let(:actions) do
271
+ RSpec::Sequencing
272
+ .run_after(0.25, "create file") do
273
+ file_path.open("wb") { |file| file.write("#{line1}\n") }
274
+ end
275
+ .then("wait for the first line") do
276
+ wait(3).for { listener1.lines.size }.to eq(1)
277
+ end
278
+ .then("append and rotate between two stats") do
279
+ file_path.open("ab") { |file| file.write("#{line2}\n") }
280
+ file_path.rename(directory.join("1G.log.1"))
281
+ file_path.open("wb") { |file| file.write("#{line3}\n") }
282
+ end
283
+ .then("wait for expectation") do
284
+ wait(4).for { listener1.lines.size }.to eq(3)
285
+ end
286
+ .then("quit") do
287
+ tailing.quit
288
+ end
289
+ end
290
+
291
+ it "the appended content of the renamed file is read before the new file" do
292
+ actions.activate_quietly
293
+ tailing.watch_this(watch_dir.to_path)
294
+ tailing.subscribe(observer)
295
+ actions.assert_no_errors
296
+ expect(listener1.lines).to eq([line1, line2, line3])
297
+ end
298
+ end
299
+
263
300
  context "copy + truncate rotation: when a logfile is copied to a new path and truncated and the open file is fully read" do
264
301
  let(:watch_dir) { directory.join("*F.log") }
265
302
  let(:file_path) { directory.join("1F.log") }
@@ -291,7 +328,7 @@ module FileWatch
291
328
  tailing.subscribe(observer)
292
329
  actions.assert_no_errors
293
330
  expect(listener1.lines).to eq([line1, line2, line3])
294
- expect(listener1.calls).to eq([:open, :accept, :accept, :accept])
331
+ expect(listener1.calls_history).to eq([:open, :accept, :accept, :accept])
295
332
  end
296
333
  end
297
334
 
@@ -333,7 +370,7 @@ module FileWatch
333
370
  end
334
371
  end
335
372
 
336
- context "? rotation: when an active file is renamed inside the glob and the reading does not lag" do
373
+ context "? rotation: when an active file is renamed inside the glob and the reading does not lag", :unix => true do
337
374
  let(:watch_dir) { directory.join("*H.log") }
338
375
  let(:file_path) { directory.join("1H.log") }
339
376
  let(:file2) { directory.join("2H.log") }
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'stud/temporary'
3
+ require_relative 'spec_helper'
4
+ require 'filewatch/sincedb_collection'
5
+
6
+ module FileWatch
7
+ describe SincedbCollection do
8
+ let(:sincedb_path) { Stud::Temporary.pathname }
9
+ let(:now) { Time.now.to_f }
10
+ let(:expired_key) { InodeStruct.new('expired', 1, 1) }
11
+ let(:active_key) { InodeStruct.new('active', 1, 1) }
12
+ let(:settings) do
13
+ Settings.from_options(
14
+ :sincedb_path => sincedb_path,
15
+ :sincedb_clean_after => 3600,
16
+ :sincedb_write_interval => 0
17
+ )
18
+ end
19
+
20
+ subject(:collection) { described_class.new(settings) }
21
+
22
+ before do
23
+ collection.set(expired_key, SincedbValue.new(42, now - 7200))
24
+ collection.set(active_key, SincedbValue.new(99, now))
25
+ collection.flush_at_interval
26
+ end
27
+
28
+ it 'removes expired entries from the collection' do
29
+ expect(collection.keys).to contain_exactly(active_key)
30
+ end
31
+
32
+ it 'does not persist expired entries' do
33
+ expect(File.read(sincedb_path)).to eq("#{active_key} 99 #{now}\n")
34
+ end
35
+ end
36
+ end
@@ -117,47 +117,56 @@ module FileWatch
117
117
 
118
118
  class TestObserver
119
119
  class Listener
120
- attr_reader :path, :lines, :calls
120
+ attr_reader :path, :lines, :calls_history
121
121
 
122
- def initialize(path, lines)
122
+ def initialize(path, lines, notification_queue)
123
123
  @path = path
124
124
  @lines = lines || Concurrent::Array.new
125
- @calls = Concurrent::Array.new
125
+ @calls_history = Concurrent::Array.new
126
+ @notification_queue = notification_queue
126
127
  end
127
128
 
128
129
  def accept(line)
129
130
  @lines << line
130
- @calls << :accept
131
+ record(:accept)
131
132
  end
132
133
 
133
134
  def deleted
134
- @calls << :delete
135
+ record(:delete)
135
136
  end
136
137
 
137
138
  def opened
138
- @calls << :open
139
+ record(:open)
139
140
  end
140
141
 
141
142
  def error
142
- @calls << :error
143
+ record(:error)
143
144
  end
144
145
 
145
146
  def eof
146
- @calls << :eof
147
+ record(:eof)
147
148
  end
148
149
 
149
150
  def timed_out
150
- @calls << :timed_out
151
+ record(:timed_out)
151
152
  end
152
153
 
153
154
  def reading_completed
154
- @calls << :reading_completed
155
+ record(:reading_completed)
156
+ end
157
+
158
+ private
159
+
160
+ def record(event)
161
+ @calls_history << event
162
+ @notification_queue << [@path, event] unless @notification_queue.nil?
155
163
  end
156
164
  end
157
165
 
158
166
  attr_reader :listeners
159
167
 
160
- def initialize(combined_lines = nil)
168
+ def initialize(combined_lines = nil, notification_queue = nil)
169
+ @notification_queue = notification_queue
161
170
  @listeners = Concurrent::Hash.new { |hash, key| hash[key] = new_listener(key, combined_lines) }
162
171
  end
163
172
 
@@ -172,7 +181,7 @@ module FileWatch
172
181
  private
173
182
 
174
183
  def new_listener(path, lines = nil)
175
- Listener.new(path, lines)
184
+ Listener.new(path, lines, @notification_queue)
176
185
  end
177
186
 
178
187
  end