Class: Tailer::StackTail

Inherits:
EventMachine::FileTail
  • Object
show all
Defined in:
lib/deployinator/stack-tail.rb

Overview

Extends FileTail to push data tailed to an EM::Channel. All open websockets subscribe to a channel for the request stack and this pushes the data to all of them at once.

Instance Method Summary collapse

Constructor Details

#initialize(filename, channel, startpos = -1)) ⇒ StackTail

Returns a new instance of StackTail.



9
10
11
12
13
# File 'lib/deployinator/stack-tail.rb', line 9

def initialize(filename, channel, startpos=-1)
  super(filename, startpos)
  @channel = channel
  @buffer = BufferedTokenizer.new
end

Instance Method Details

#receive_data(data) ⇒ Object

This method is called whenever FileTail receives and inotify event for the tailed file. It breaks up the data per line and pushes a line at a time. This is to prevent the last javascript line from being broken up over 2 pushes thus breaking the eval on the front end.



19
20
21
22
23
# File 'lib/deployinator/stack-tail.rb', line 19

def receive_data(data)
  @buffer.extract(data).each do |line|
    @channel.push line
  end
end