Class: Typhon

Inherits:
Object
  • Object
show all
Defined in:
lib/typhon.rb,
lib/typhon/log.rb,
lib/typhon/head.rb,
lib/typhon/heads.rb,
lib/typhon/config.rb,
lib/typhon/ratelimit.rb,
lib/typhon/natsclient.rb,
lib/typhon/stompclient.rb

Defined Under Namespace

Classes: Config, Head, Heads, Log, NatsClient, RateLimit, StompClient

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "/etc/typhon") ⇒ Typhon

Returns a new instance of Typhon.



62
63
64
65
66
67
68
69
70
71
# File 'lib/typhon.rb', line 62

def initialize(path="/etc/typhon")
  @configdir = path

  Config[:configdir] = path
  Config.loadconfig

  @heads = Heads.new
  @stomp = nil
  @nats = nil
end

Instance Attribute Details

#headsObject (readonly)

Returns the value of attribute heads.



60
61
62
# File 'lib/typhon.rb', line 60

def heads
  @heads
end

Class Method Details

.daemonizeObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/typhon.rb', line 46

def daemonize
  fork do
    Process.setsid
    exit if fork
    Dir.chdir('/tmp')
    STDIN.reopen('/dev/null')
    STDOUT.reopen('/dev/null', 'a')
    STDERR.reopen('/dev/null', 'a')

    yield
  end
end

.filesObject



19
20
21
# File 'lib/typhon.rb', line 19

def files
  Heads.heads.keys
end

.grow(options, &blk) ⇒ Object



23
24
25
26
27
28
# File 'lib/typhon.rb', line 23

def grow(options, &blk)
  raise "Heads need a name" unless options[:name]
  raise "Heads need files" unless options[:files]

  Heads.register_head(options[:name], options[:files], blk)
end

.headsObject



15
16
17
# File 'lib/typhon.rb', line 15

def heads
  Heads.heads
end

.natsObject



34
35
36
# File 'lib/typhon.rb', line 34

def nats
  @nats
end

.nats=(nats) ⇒ Object



30
31
32
# File 'lib/typhon.rb', line 30

def nats=(nats)
  @nats = nats
end

.stompObject



42
43
44
# File 'lib/typhon.rb', line 42

def stomp
  @stomp
end

.stomp=(stomp) ⇒ Object



38
39
40
# File 'lib/typhon.rb', line 38

def stomp=(stomp)
  @stomp = stomp
end

Instance Method Details

#start_natsObject



73
74
75
76
# File 'lib/typhon.rb', line 73

def start_nats
  @nats = Typhon::NatsClient.new(Config[:nats])
  Typhon.nats = @nats
end

#start_stompObject



78
79
80
81
82
# File 'lib/typhon.rb', line 78

def start_stomp
  Log.debug("Connecting to Stomp Server %s:%d" % [ Config[:stomp][:server], Config[:stomp][:port] ])
  @stomp = EM.connect Config[:stomp][:server], Config[:stomp][:port], Typhon::StompClient, {:auto_reconnect => true, :timeout => 2}
  Typhon.stomp = @stomp
end

#tailObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/typhon.rb', line 84

def tail
  EM.run do
    @heads.loadheads

    start_stomp if Config[:stomp]
    start_nats if Config[:nats]

    EM.add_periodic_timer(10) do
      @heads.loadheads
    end

    if Config[:stat_log_frequency] > 0
      EM.add_periodic_timer(Config[:stat_log_frequency]) do
        @heads.log_stats
      end
    end
  end
end