#!/usr/bin/env ruby $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib") require "rubygems" require "optparse" require "keen" options = { :env => "production", } required = [ :storage_mode, # this has to be something understood by Keen::Client.process_queue(options) ] begin parser = OptionParser.new() parser.banner = "#{File.basename($0)} []\n\n" parser.on("-e", "--env ENVIRONMENT", "The environment to run in. Default: production") do |e| options[:env] = e end parser.on("-p", "--storage_mode redis|flat_file", "Where is the queue you're reading?") do |f| options[:storage_mode] = f end parser.on_tail("-h", "--help", "This help.") do puts parser exit end opts = parser.parse(ARGV) rescue => e $stderr.puts "\nERROR: #{e.message}\n\n" $stderr.puts parser.help exit(-1) end # confirm required options: required.each do |key| raise OptionParser::MissingArgument.new("you must send `#{key}` when running this command") if options[key].nil? end storage_handler = Keen::Client.create_new_storage_handler(options[:storage_mode]) worker = Keen::Async::Worker.new(storage_handler) puts worker.process_queue