eventmachine-tail 0.4.20100903005209 → 0.5.20101005181243
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.
- data/lib/em/filetail.rb +4 -4
- data/lib/em/globwatcher.rb +28 -13
- metadata +4 -4
data/lib/em/filetail.rb
CHANGED
@@ -89,13 +89,13 @@ class EventMachine::FileTail
|
|
89
89
|
EventMachine::next_tick do
|
90
90
|
open
|
91
91
|
if (startpos == -1)
|
92
|
-
@file.sysseek(0, IO::SEEK_END)
|
92
|
+
@position = @file.sysseek(0, IO::SEEK_END)
|
93
93
|
# TODO(sissel): if we don't have inotify or kqueue, should we
|
94
94
|
# schedule a next read, here?
|
95
95
|
# Is there a race condition between setting the file position and
|
96
96
|
# watching given the two together are not atomic?
|
97
97
|
else
|
98
|
-
@file.sysseek(startpos, IO::SEEK_SET)
|
98
|
+
@position = @file.sysseek(startpos, IO::SEEK_SET)
|
99
99
|
schedule_next_read
|
100
100
|
end
|
101
101
|
watch
|
@@ -331,13 +331,13 @@ class EventMachine::FileTail
|
|
331
331
|
elsif (filestat.size < @filestat.size)
|
332
332
|
# If the file size shrank, assume truncation and seek to the beginning.
|
333
333
|
@logger.info("File likely truncated... #{path}")
|
334
|
-
@file.sysseek(0, IO::SEEK_SET)
|
334
|
+
@position = @file.sysseek(0, IO::SEEK_SET)
|
335
335
|
schedule_next_read
|
336
336
|
end
|
337
337
|
end # def handle_fstat
|
338
338
|
|
339
339
|
def to_s
|
340
|
-
return "#{self.class.name}(#{@path}) @ pos:#{@
|
340
|
+
return "#{self.class.name}(#{@path}) @ pos:#{@position}"
|
341
341
|
end # def to_s
|
342
342
|
end # class EventMachine::FileTail
|
343
343
|
|
data/lib/em/globwatcher.rb
CHANGED
@@ -171,20 +171,25 @@ end # class EventMachine::FileGlobWatch
|
|
171
171
|
class EventMachine::FileGlobWatchTail < EventMachine::FileGlobWatch
|
172
172
|
# Initialize a new file glob tail.
|
173
173
|
#
|
174
|
-
# path
|
175
|
-
# handler
|
174
|
+
# * path - glob or file path (string)
|
175
|
+
# * handler - a module or subclass of EventMachine::FileTail
|
176
176
|
# See also EventMachine::file_tail
|
177
|
-
# interval
|
178
|
-
# exclude
|
177
|
+
# * interval - how often (seconds) the glob path should be scanned
|
178
|
+
# * exclude - an array of Regexp (or anything with .match) for
|
179
179
|
# excluding from things to tail
|
180
|
+
#
|
180
181
|
# The remainder of arguments are passed to EventMachine::file_tail as
|
181
|
-
# EventMachine::file_tail(path_found, handler, *args)
|
182
|
+
# EventMachine::file_tail(path_found, handler, *args, &block)
|
182
183
|
public
|
183
|
-
def initialize(path, handler=nil, interval=60, exclude=[], *args)
|
184
|
+
def initialize(path, handler=nil, interval=60, exclude=[], *args, &block)
|
184
185
|
super(path, interval)
|
185
186
|
@handler = handler
|
186
187
|
@args = args
|
187
188
|
@exclude = exclude
|
189
|
+
|
190
|
+
if block_given?
|
191
|
+
@handler = block
|
192
|
+
end
|
188
193
|
end # def initialize
|
189
194
|
|
190
195
|
public
|
@@ -200,7 +205,11 @@ class EventMachine::FileGlobWatchTail < EventMachine::FileGlobWatch
|
|
200
205
|
end
|
201
206
|
@logger.info "#{self.class}: Watching #{path}"
|
202
207
|
|
203
|
-
|
208
|
+
if @handler.is_a? Proc
|
209
|
+
EventMachine::file_tail(path, nil, *@args, &@handler)
|
210
|
+
else
|
211
|
+
EventMachine::file_tail(path, @handler, *@args)
|
212
|
+
end
|
204
213
|
rescue Errno::EACCES => e
|
205
214
|
file_error(path, e)
|
206
215
|
rescue Errno::EISDIR => e
|
@@ -228,15 +237,21 @@ end # class EventMachine::FileGlobWatchHandler
|
|
228
237
|
module EventMachine
|
229
238
|
# Watch a glob and tail any files found.
|
230
239
|
#
|
231
|
-
#
|
232
|
-
# handler
|
240
|
+
# * glob - a string path or glob, such as /var/log/*.log
|
241
|
+
# * handler - a module or subclass of EventMachine::FileGlobWatchTail.
|
242
|
+
# handler can be omitted if you give a block.
|
243
|
+
#
|
244
|
+
# If you give a block and omit the handler parameter, then the behavior
|
245
|
+
# is that your block is called for every line read from any file the same
|
246
|
+
# way EventMachine::file_tail does when called with a block.
|
247
|
+
#
|
233
248
|
# See EventMachine::FileGlobWatchTail for the callback methods.
|
234
|
-
|
235
|
-
|
249
|
+
# See EventMachine::file_tail for more information about block behavior.
|
250
|
+
def self.glob_tail(glob, handler=nil, *args, &block)
|
251
|
+
handler = EventMachine::FileGlobWatchTail if handler == nil
|
236
252
|
args.unshift(glob)
|
237
253
|
klass = klass_from_handler(EventMachine::FileGlobWatchTail, handler, *args)
|
238
|
-
c = klass.new(*args)
|
239
|
-
yield c if block_given?
|
254
|
+
c = klass.new(*args, &block)
|
240
255
|
return c
|
241
256
|
end
|
242
257
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 20101005181243
|
9
|
+
version: 0.5.20101005181243
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jordan Sissel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-05 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|