eventmachine-tail 0.6.5 → 0.6.6
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 +5 -5
- data/lib/em/filetail.rb +2 -3
- data/lib/em/globwatcher.rb +18 -1
- data/samples/globwatch.rb +4 -0
- data/test/test_glob.rb +44 -0
- metadata +27 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96b3872cfc6a1c388aa9ee4d8f67ae2b69cc7a9ae5fdbb39449a9a293702fb37
|
4
|
+
data.tar.gz: c268790026a0f65cff3d521dcd366db1ab848f685f4ccd9aa69c024bb09bf406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15956a61dd9222dd09147623d7b8357850d2995ed5a270039b326e623d33916ca1fd2321920a1334ce5a4398a0db49e4134f32dacb1148153cb133cc202281da
|
7
|
+
data.tar.gz: 507f39f080224e3784e23bcaf1ba8c680f54d47e277fd134c8becb30089aa33b415eb4e9e0cbe035ec30c8d3a8598ca1505d715a63ec40295fc376c329e5abdc
|
data/lib/em/filetail.rb
CHANGED
@@ -173,7 +173,6 @@ class EventMachine::FileTail
|
|
173
173
|
schedule_next_read
|
174
174
|
elsif status == :moved
|
175
175
|
# read to EOF, then reopen.
|
176
|
-
@reopen_on_eof = true
|
177
176
|
schedule_next_read
|
178
177
|
elsif status == :unbind
|
179
178
|
# :unbind is called after the :deleted handler
|
@@ -188,7 +187,7 @@ class EventMachine::FileTail
|
|
188
187
|
def open
|
189
188
|
return if @closed
|
190
189
|
@file.close if @file && !@file.closed?
|
191
|
-
return unless File.
|
190
|
+
return unless File.exist?(@path)
|
192
191
|
begin
|
193
192
|
@logger.debug "Opening file #{@path}"
|
194
193
|
@file = File.open(@path, "r")
|
@@ -228,7 +227,7 @@ class EventMachine::FileTail
|
|
228
227
|
def watch
|
229
228
|
@watch.stop_watching if @watch
|
230
229
|
@symlink_timer.cancel if @symlink_timer
|
231
|
-
return unless File.
|
230
|
+
return unless File.exist?(@path)
|
232
231
|
|
233
232
|
@logger.debug "Starting watch on #{@path}"
|
234
233
|
callback = proc { |what| notify(what) }
|
data/lib/em/globwatcher.rb
CHANGED
@@ -81,6 +81,15 @@ class EventMachine::FileGlobWatch
|
|
81
81
|
"module?")
|
82
82
|
end # def file_found
|
83
83
|
|
84
|
+
# This method is called when a file is modified.
|
85
|
+
#
|
86
|
+
# * path - The string path of the file modified
|
87
|
+
#
|
88
|
+
# You AREN'T required to implement this in your sublcass or module
|
89
|
+
public
|
90
|
+
def file_modified(path)
|
91
|
+
end
|
92
|
+
|
84
93
|
# This method is called when a file is deleted.
|
85
94
|
#
|
86
95
|
# * path - the string path of the file deleted
|
@@ -104,7 +113,10 @@ class EventMachine::FileGlobWatch
|
|
104
113
|
fileinfo = FileInfo.new(path) rescue next
|
105
114
|
# Skip files that have the same inode (renamed or hardlinked)
|
106
115
|
known_files.delete(fileinfo.stat.ino)
|
107
|
-
|
116
|
+
if @files.include?(fileinfo.stat.ino)
|
117
|
+
next unless modified(fileinfo)
|
118
|
+
file_modified(path)
|
119
|
+
end
|
108
120
|
|
109
121
|
track(fileinfo)
|
110
122
|
file_found(path)
|
@@ -144,6 +156,11 @@ class EventMachine::FileGlobWatch
|
|
144
156
|
#end
|
145
157
|
end # def watch
|
146
158
|
|
159
|
+
# Tells if a file has been modified since last time
|
160
|
+
def modified(fileinfo)
|
161
|
+
not @files[fileinfo.stat.ino].stat.mtime == fileinfo.stat.mtime
|
162
|
+
end
|
163
|
+
|
147
164
|
private
|
148
165
|
class FileWatcher < EventMachine::FileWatch
|
149
166
|
def initialize(globwatch, &block)
|
data/samples/globwatch.rb
CHANGED
data/test/test_glob.rb
CHANGED
@@ -32,6 +32,26 @@ class Watcher < EventMachine::FileGlobWatch
|
|
32
32
|
end
|
33
33
|
end # class Reader
|
34
34
|
|
35
|
+
class ModificationWatcher < EventMachine::FileGlobWatch
|
36
|
+
def initialize(path, interval, data, testobj)
|
37
|
+
super(path, interval)
|
38
|
+
@data = data
|
39
|
+
@testobj = testobj
|
40
|
+
end # def initialize
|
41
|
+
|
42
|
+
def file_found(path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_deleted(patH)
|
46
|
+
end
|
47
|
+
|
48
|
+
def file_modified(path)
|
49
|
+
@testobj.assert(@data.include?(path), "Expected #{path} in \n#{@data.join("\n")}")
|
50
|
+
@data.delete(path)
|
51
|
+
@testobj.finish if @data.length == 0
|
52
|
+
end
|
53
|
+
end # class ModificationWatcher
|
54
|
+
|
35
55
|
class TestGlobWatcher < Test::Unit::TestCase
|
36
56
|
include EventMachineTailTestHelpers
|
37
57
|
SLEEPMAX = 1
|
@@ -142,5 +162,29 @@ class TestGlobWatcher < Test::Unit::TestCase
|
|
142
162
|
end
|
143
163
|
end
|
144
164
|
end # def test_glob_ignores_file_renames
|
165
|
+
|
166
|
+
def test_glob_finds_modified_files_at_runtime
|
167
|
+
EM.run do
|
168
|
+
abort_after_timeout(SLEEPMAX * @data.length + 10)
|
169
|
+
|
170
|
+
datacopy = @data.clone
|
171
|
+
|
172
|
+
# To test if file edit is detected, file must exist first
|
173
|
+
datacopy.each do |filename|
|
174
|
+
File.new(filename, "w").close
|
175
|
+
end
|
176
|
+
|
177
|
+
EM::watch_glob("#{@dir}/*", ModificationWatcher, @watchinterval, @data.clone, self)
|
178
|
+
|
179
|
+
sleep(2) # Modification time resolution is 1 second, so we need to allow mtimes to change
|
180
|
+
timer = EM::PeriodicTimer.new(0.2) do
|
181
|
+
File.open(datacopy.shift, "w") do |f|
|
182
|
+
f.puts("LOLCAT!")
|
183
|
+
end
|
184
|
+
sleep(rand * SLEEPMAX)
|
185
|
+
timer.cancel if datacopy.length == 0
|
186
|
+
end
|
187
|
+
end # EM.run
|
188
|
+
end # def test_glob_finds_modified_files_at_runtime
|
145
189
|
end # class TestGlobWatcher
|
146
190
|
|
metadata
CHANGED
@@ -1,40 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventmachine-tail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: eventmachine
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- -
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- -
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: test-unit
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
25
38
|
- !ruby/object:Gem::Version
|
26
39
|
version: '0'
|
27
40
|
description: Add file 'tail' implemented with EventMachine. Also includes a 'glob
|
28
41
|
watch' class for watching a directory pattern for new matches, like /var/log/*.log
|
29
42
|
email: jls@semicomplete.com
|
30
43
|
executables:
|
31
|
-
- rtail
|
32
44
|
- emtail
|
45
|
+
- rtail
|
33
46
|
extensions: []
|
34
47
|
extra_rdoc_files: []
|
35
48
|
files:
|
36
|
-
-
|
49
|
+
- bin/emtail
|
50
|
+
- bin/rtail
|
37
51
|
- lib/em/filetail.rb
|
52
|
+
- lib/em/globwatcher.rb
|
38
53
|
- lib/eventmachine-tail.rb
|
39
54
|
- samples/glob-tail.rb
|
40
55
|
- samples/globwatch.rb
|
@@ -44,30 +59,26 @@ files:
|
|
44
59
|
- test/test_filetail.rb
|
45
60
|
- test/test_glob.rb
|
46
61
|
- test/testcase_helpers.rb
|
47
|
-
- bin/emtail
|
48
|
-
- bin/rtail
|
49
62
|
homepage: http://code.google.com/p/semicomplete/wiki/EventMachineTail
|
50
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- BSD-3-Clause
|
51
65
|
metadata: {}
|
52
|
-
post_install_message:
|
53
66
|
rdoc_options: []
|
54
67
|
require_paths:
|
55
68
|
- lib
|
56
69
|
- lib
|
57
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
71
|
requirements:
|
59
|
-
- -
|
72
|
+
- - ">="
|
60
73
|
- !ruby/object:Gem::Version
|
61
74
|
version: '0'
|
62
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
76
|
requirements:
|
64
|
-
- -
|
77
|
+
- - ">="
|
65
78
|
- !ruby/object:Gem::Version
|
66
79
|
version: '0'
|
67
80
|
requirements: []
|
68
|
-
|
69
|
-
rubygems_version: 2.0.14
|
70
|
-
signing_key:
|
81
|
+
rubygems_version: 3.6.7
|
71
82
|
specification_version: 4
|
72
83
|
summary: eventmachine tail - a file tail implementation with glob support
|
73
84
|
test_files: []
|