Class: CFTools::Watch

Inherits:
CF::App::Base
  • Object
show all
Defined in:
lib/tools-cf-plugin/watch.rb

Constant Summary collapse

REPLY_PREFIX =
"`- reply to "
COLUMN_WIDTH =
30

Instance Method Summary collapse

Instance Method Details

#color?Boolean

colorize if told to; don’t check if output is tty

Returns:

  • (Boolean)


11
12
13
# File 'lib/tools-cf-plugin/watch.rb', line 11

def color?
  input[:color]
end

#preconditionObject



8
# File 'lib/tools-cf-plugin/watch.rb', line 8

def precondition; end

#watchObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tools-cf-plugin/watch.rb', line 34

def watch
  app = get_app(input[:app])
  host = input[:host]
  port = input[:port]
  user = input[:user]
  pass = input[:password]
  subjects = input[:subjects] || [">"]

  @requests = {}
  @seen_apps = {}
  @request_ticker = 0

  $stdout.sync = true

  watching_nats(
      :uri => "nats://#{user}:#{pass}@#{host}:#{port}",
      :logs => input[:logs],
      :subjects => subjects) do |msg, reply, sub, time|
    begin
      time ||= Time.now.strftime("%r")

      if @requests.include?(sub)
        process_response(sub, reply, msg, app, time)
      elsif !app || msg.include?(app.guid)
        process_message(sub, reply, msg, app, time)
      end
    rescue => e
      line c("couldn't deal w/ #{sub} '#{msg}': #{e.class}: #{e}", :error)
    end
  end
end