Skip to content

Instantly share code, notes, and snippets.

@ctrochalakis
Created June 30, 2010 08:42
Show Gist options
  • Save ctrochalakis/458403 to your computer and use it in GitHub Desktop.
Save ctrochalakis/458403 to your computer and use it in GitHub Desktop.
eventmachine-tail bug
touch tailme
# Tail the same file twice
tailer.rb tailme
echo "smth" |cat >tailme
# results:
Tailing tailme
Tailing tailme
tailme: smth
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