1 #!/usr/bin/env rackup -s thin
6 # Tested with 150 spawned tails on OS X
8 # Created by James Tucker on 2008-06-18.
9 # Copyright 2008 James Tucker <raggi@rubyforge.org>.
11 # Uncomment if appropriate for you..
15 tail_log_file = ENV["TAIL_LOG_FILE"] or abort "TAIL_LOG_FILE= env must be set"
16 unless ::File.file?(tail_log_file) && ::File.readable?(tail_log_file)
17 abort "#{tail_log_file} must be a readable regular file"
21 include EventMachine::Deferrable
25 # make sure to flush out the queue before closing the connection
28 @queue.shift.each{|chunk| @body_callback.call(chunk) }
34 return unless @body_callback
35 EventMachine::next_tick do
36 next unless body = @queue.shift
38 @body_callback.call(chunk)
40 schedule_dequeue unless @queue.empty?
57 attr_accessor :callback
59 def receive_data(data)
60 @callback.call([data])
70 AsyncResponse = [-1, {}, []].freeze
74 body = DeferrableBody.new
76 EventMachine::next_tick do
78 env['async.callback'].call [200, {'Content-Type' => 'text/html'}, body]
80 body.call ["<h1>Async Tailer</h1><pre>"]
84 EventMachine::popen("tail -f #{ENV["TAIL_LOG_FILE"]}", TailRenderer) do |t|
88 # If for some reason we 'complete' body, close the tail.
93 # If for some reason the client disconnects, close the tail.