Created
June 30, 2010 08:42
-
-
Save ctrochalakis/458403 to your computer and use it in GitHub Desktop.
eventmachine-tail bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
touch tailme | |
# Tail the same file twice | |
tailer.rb tailme | |
echo "smth" |cat >tailme | |
# results: | |
Tailing tailme | |
Tailing tailme | |
tailme: smth |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
require 'eventmachine-tail' | |
$DEBUG= true | |
class Reader < EventMachine::FileTail | |
def initialize(path, startpos=-1) | |
super(path, startpos) | |
puts "Tailing #{path}" | |
@buffer = BufferedTokenizer.new | |
end | |
def receive_data(data) | |
@buffer.extract(data).each do |line| | |
puts "#{path}: #{line}" | |
end | |
end | |
end | |
def main(args) | |
if args.length == 0 | |
puts "Usage: #{$0} <path> [path2] [...]" | |
return 1 | |
end | |
EventMachine.run do | |
args.each do |path| | |
EventMachine::file_tail(path, Reader) | |
end | |
end | |
end # def main | |
exit(main(ARGV)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment