Class: LogSender

Inherits:
Object
  • Object
show all
Defined in:
lib/gush/control/log_sender.rb

Constant Summary collapse

ROWS =
25

Instance Method Summary collapse

Constructor Details

#initialize(socket, redis, commands, channel) ⇒ LogSender

Returns a new instance of LogSender.



4
5
6
7
8
9
# File 'lib/gush/control/log_sender.rb', line 4

def initialize(socket, redis, commands, channel)
  @redis = redis
  @commands = commands
  @channel = channel
  @socket = socket
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gush/control/log_sender.rb', line 11

def run
  Thread.new do
    tail = [0, message_count - ROWS].max
    head = (tail - 1).downto(0).each_slice(ROWS)

    loop do
      if commands.empty?
        method = :append
        logs = fetch_logs_after(tail)
        tail += logs.size
      else
        case commands.pop
        when 'prepend'
          method = :prepend
          begin
            logs = fetch_range(head.next)
          rescue StopIteration
            logs = []
          end
        end
      end

      send_lines(sanitize_logs(logs), method)
      sleep 1
    end
  end
end