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

#preconditionObject



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

def precondition; end

#watchObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tools-cf-plugin/watch.rb', line 26

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("nats://#{user}:#{pass}@#{host}:#{port}", subjects) do |msg, reply, sub|
    begin
      if @requests.include?(sub)
        process_response(sub, reply, msg, app)
      elsif !app || msg.include?(app.guid)
        process_message(sub, reply, msg, app)
      end
    rescue => e
      line c("couldn't deal w/ #{sub} '#{msg}': #{e.class}: #{e}", :error)
    end
  end
end