Class: Firehose::CLI
- Inherits:
-
Thor
- Object
- Thor
- Firehose::CLI
- Defined in:
- lib/firehose/cli.rb
Instance Method Summary collapse
- #consume(uri) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #javascript ⇒ Object
- #publish(uri, payload = nil) ⇒ Object
- #server ⇒ Object
- #version ⇒ Object
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 [:concurrency].times { Firehose::Client::Consumer.parse(uri).request } end end |
#javascript ⇒ Object
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 = [:times] ttl = [:ttl] EM.run do # TODO I think this can be cleaned up so the top-level if/else can be ditched. if interval = [: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 |