notified_tail 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notified_tail.rb +3 -3
- data/notified_tail.gemspec +1 -1
- data/spec/lib/notified_tail_spec.rb +50 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa8eddca759a4256d8851d8030427c2e0e6acd7
|
4
|
+
data.tar.gz: 2f8488e69e14240075c0e1addf5bf81a68d0b37a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a00b5626010f98902847ddf6ee1e14148d94d3d2c07b7636aa49f1a5a3f52ef7ab139d1fb6b576397f1c4b0df2f3148118d4d368574bafd8eb6f7a54fc5de1e
|
7
|
+
data.tar.gz: 1d159c3305817fddf09c81dc6175bf65497647a94d9ba0923954223ee00430c5165a66c8a0785b7ec4f0a00c54f8016d115c1533208feac28273f023ffe8a0c2
|
data/lib/notified_tail.rb
CHANGED
@@ -16,7 +16,7 @@ class NotifiedTail
|
|
16
16
|
new.tail(file_path, opts, &on_line)
|
17
17
|
end
|
18
18
|
|
19
|
-
def tail(file_path, opts, &on_line)
|
19
|
+
def tail(file_path, opts={}, &on_line)
|
20
20
|
@file_path = file_path
|
21
21
|
@stopped = false
|
22
22
|
seek_end = opts.fetch(:seek_end, true)
|
@@ -64,12 +64,12 @@ class NotifiedTail
|
|
64
64
|
require 'rb-kqueue'
|
65
65
|
@queue = KQueue::Queue.new
|
66
66
|
@queue.watch_file(file_path, :extend) { block.call }
|
67
|
-
@queue.run
|
67
|
+
@queue.run unless @stopped
|
68
68
|
when /linux/
|
69
69
|
require 'rb-inotify'
|
70
70
|
@queue = INotify::Notifier.new
|
71
71
|
@queue.watch(file_path, :modify) { block.call }
|
72
|
-
@queue.run
|
72
|
+
@queue.run unless @stopped
|
73
73
|
else
|
74
74
|
poll(file_path, &block)
|
75
75
|
end
|
data/notified_tail.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'notified_tail'
|
7
|
-
spec.version = '0.2.
|
7
|
+
spec.version = '0.2.2'
|
8
8
|
spec.authors = ['Peter Winton']
|
9
9
|
spec.email = ['pwinton@indigobio.com']
|
10
10
|
spec.summary = %q{Low latency file tailing in ruby}
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'securerandom'
|
3
3
|
require 'notified_tail'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
describe NotifiedTail do
|
6
7
|
describe '#tail' do
|
7
8
|
let!(:seek_end) { false }
|
8
9
|
let!(:force_poll) { false }
|
10
|
+
let!(:fn) { SecureRandom.uuid }
|
11
|
+
after(:each) { File.delete(fn) }
|
9
12
|
|
10
13
|
shared_examples 'tail -f' do
|
11
14
|
let!(:lines) { [] }
|
12
|
-
let!(:fn) { SecureRandom.uuid }
|
13
|
-
after(:each) { File.delete(fn) }
|
14
15
|
|
15
16
|
it 'tails a growing file, line by line' do
|
16
17
|
|
@@ -35,11 +36,6 @@ describe NotifiedTail do
|
|
35
36
|
append(fn, "line with words\n")
|
36
37
|
watcher.join
|
37
38
|
end
|
38
|
-
|
39
|
-
def append(fn, text)
|
40
|
-
File.open(fn, 'a') { |f| f.print(text) }
|
41
|
-
sleep(0.1)
|
42
|
-
end
|
43
39
|
end
|
44
40
|
|
45
41
|
shared_examples 'tail -f -n 9999PB' do
|
@@ -75,5 +71,52 @@ describe NotifiedTail do
|
|
75
71
|
it_behaves_like 'tail -f -n 9999PB'
|
76
72
|
end
|
77
73
|
|
74
|
+
it 'can be stopped before new data is tailed' do
|
75
|
+
File.write(fn, "hello\n")
|
76
|
+
|
77
|
+
thread = Thread.start do
|
78
|
+
notifier = NotifiedTail.new
|
79
|
+
notifier.tail(fn, seek_end: false) do |line|
|
80
|
+
print "saw #{line.inspect}\n"
|
81
|
+
if line == 'hello'
|
82
|
+
Thread.start do
|
83
|
+
expect(notifier.instance_variable_get(:@queue)).to be_nil
|
84
|
+
notifier.stop
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
thread.join
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'can be stopped after new data is tailed (must write to the file)' do
|
94
|
+
thread = Thread.start do
|
95
|
+
notifier = NotifiedTail.new
|
96
|
+
notifier.tail(fn, seek_end: false) do |line|
|
97
|
+
print "saw #{line.inspect}\n"
|
98
|
+
if line == 'there'
|
99
|
+
Thread.start do
|
100
|
+
expect(notifier.instance_variable_get(:@queue)).to_not be_nil
|
101
|
+
notifier.stop
|
102
|
+
File.open(notifier.file_path, 'a'){|f| f.print("\n")}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
sleep(0.25) # let the notifier start up
|
108
|
+
|
109
|
+
append(fn, "hello\n")
|
110
|
+
sleep(0.5)
|
111
|
+
append(fn, "there\n")
|
112
|
+
|
113
|
+
thread.join
|
114
|
+
end
|
115
|
+
|
116
|
+
def append(fn, text)
|
117
|
+
File.open(fn, 'a') { |f| f.print(text) }
|
118
|
+
sleep(0.1)
|
119
|
+
end
|
120
|
+
|
78
121
|
end
|
79
122
|
end
|