class Firehose::CLI

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/firehose/cli.rb, line 11
def initialize(*args)
  super
  # Disable buffering to $stdio for Firehose.logger
  $stdout.sync = true
end

Public Instance Methods

consume(uri) click to toggle source
# File lib/firehose/cli.rb, line 43
def consume(uri)
  EM.run do
    options[:concurrency].times { Firehose::Client::Consumer.parse(uri).request }
  end
end
javascript() click to toggle source
# 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) click to toggle source
# 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
server() click to toggle source
# 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
version() click to toggle source
# File lib/firehose/cli.rb, line 24
def version
  puts %[Firehose #{Firehose::VERSION} "#{Firehose::CODENAME}"]
end