Class: Firehose::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/firehose/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
15
# File 'lib/firehose/cli.rb', line 11

def initialize(*args)
  super
  # Disable buffering to $stdio for Firehose.logger
  $stdout.sync = true
end

Instance Method Details

#consume(uri) ⇒ Object



43
44
45
46
47
# File 'lib/firehose/cli.rb', line 43

def consume(uri)
  EM.run do
    options[:concurrency].times { Firehose::Client::Consumer.parse(uri).request }
  end
end

#javascriptObject



18
19
20
21
# File 'lib/firehose/cli.rb', line 18

def javascript
  $stderr.puts "DEPRECATION WARNING: Firehose JS assets have been moved to https://github.com/firehoseio/js_client"
  $stdout.puts Firehose::Assets::Sprockets.javascript
end

#publish(uri, payload = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/firehose/cli.rb', line 53

def publish(uri, payload=nil)
  payload     ||= $stdin.read
  client      = Firehose::Client::Producer::Http.new(uri)
  path        = ::URI.parse(uri).path
  times       = options[:times]
  ttl         = options[:ttl]

  EM.run do
    # TODO I think this can be cleaned up so the top-level if/else can be ditched.
    if interval = options[:interval]
      # Publish messages at a forced interval.
      EM.add_periodic_timer interval do
        client.publish(payload).to(path, :ttl => ttl)
        EM.stop if times && (times-=1).zero?
      end
    else
      # Publish messages as soon as the last message was published.
      worker = Proc.new do
        client.publish(payload).to(path, :ttl => ttl)
        times && (times-=1).zero? ? EM.stop : worker.call
      end
      worker.call
    end
  end
end

#serverObject



32
33
34
35
36
37
38
39
# File 'lib/firehose/cli.rb', line 32

def server
  begin
    Firehose::Server::App.new(options).start
  rescue => e
    Firehose.logger.error "#{e.message}: #{e.backtrace}"
    raise e
  end
end

#versionObject



24
25
26
# File 'lib/firehose/cli.rb', line 24

def version
  puts %[Firehose #{Firehose::VERSION} "#{Firehose::CODENAME}"]
end