#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path('..', __dir__)) require 'bundler/setup' require 'app/firehose_client' $stdout.sync = true if ENV['ARLOG'] == '1' ActiveRecord::Base.logger = Logger.new(STDOUT) else ActiveRecord::Base.logger = nil end def print_help puts "Usage: #{$0} [options...]" puts "Options:" puts " -r12345 = start from cursor 12345" end firehose = FirehoseClient.new args = ARGV.dup while arg = args.shift case arg when /^\-r(\d+)$/ firehose.start_cursor = $1.to_i when '-h', '--help' print_help exit 0 else puts "Unrecognized option: #{arg}" print_help exit 1 end end trap("SIGINT") { firehose.log "Stopping..." EM.add_timer(0) { firehose.stop } } trap("SIGTERM") { firehose.log "Shutting down the service..." EM.add_timer(0) { firehose.stop } } firehose.start