class Banter::CLI
Attributes
pidfile[RW]
process_name[RW]
subscribers[RW]
Public Instance Methods
parse(args = ARGV)
click to toggle source
Method to support parsing of arguments passed through the command line
# File lib/banter/cli.rb, line 16 def parse(args = ARGV) optparse = OptionParser.new do |opts| opts.banner = "Usage: bundle exec start_subscribers [options]" opts.on '-P', '--pidfile PATH', "path to pidfile" do |arg| @pidfile = arg end opts.on("-o", "--only [SUBSCRIBERS]", "comma separated name of subsriber classes that should be run") do |subscribers| @subscribers = subscribers.split(/\,/) end opts.on '-r', '--require [PATH|DIR]', "Location of Rails application with workers or file to require" do |arg| @require_path = arg end opts.on '-n', '--name [PROCESS_NAME]', "Name of the process" do |arg| @process_name = arg end opts.on '-v', '--version', "Print version and exit" do puts "Banter #{Banter::VERSION}" abort end end optparse.parse!(args) end
remove_pid()
click to toggle source
# File lib/banter/cli.rb, line 65 def remove_pid return unless pidfile File.delete(pidfile) if File.exist?(pidfile) end
require_path()
click to toggle source
# File lib/banter/cli.rb, line 51 def require_path @require_path || "." end
run()
click to toggle source
# File lib/banter/cli.rb, line 44 def run change_process_name load_environment write_pidfile load_subscribers end
subscriber_classes()
click to toggle source
@return [Array] returns array of subscriber classes that will be executed by the CLI
# File lib/banter/cli.rb, line 57 def subscriber_classes if subscribers.present? subscribers.map(&:constantize) else Banter::Subscriber.class_variable_get(:@@registered_subscribers) end end
Private Instance Methods
change_process_name()
click to toggle source
# File lib/banter/cli.rb, line 99 def change_process_name $PROGRAM_NAME = @process_name || "banter_subscriber" end
load_environment()
click to toggle source
# File lib/banter/cli.rb, line 72 def load_environment if require_path raise ArgumentError, "#{require_path} does not exist" unless File.exist?(require_path) end if File.directory?(require_path) require 'rails' require 'banter/railtie' require File.expand_path("#{require_path}/config/environment.rb") ::Rails.application.eager_load! else require require_path end end
load_subscribers()
click to toggle source
# File lib/banter/cli.rb, line 94 def load_subscribers Banter::Server::SubscriberServer.instance.set_workers(subscriber_classes) Banter::Server::SubscriberServer.instance.start end
write_pidfile()
click to toggle source
# File lib/banter/cli.rb, line 87 def write_pidfile return unless pidfile File.open(pidfile, 'w') do |f| f.puts Process.pid end end