class Maitredee::CLI::Runner
Public Instance Methods
load_rails()
click to toggle source
# File lib/maitredee/cli/runner.rb, line 81 def load_rails # Adapted from: https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/cli.rb require 'rails' if ::Rails::VERSION::MAJOR < 4 require File.expand_path('config/environment.rb') ::Rails.application.eager_load! else # Painful contortions, see 1791 for discussion require File.expand_path('config/application.rb') if ::Rails::VERSION::MAJOR == 4 ::Rails::Application.initializer 'maitredee.eager_load' do ::Rails.application.config.eager_load = true end end require 'shoryuken/extensions/active_job_adapter' if Shoryuken.active_job? require File.expand_path('config/environment.rb') end end
require_workers(required)
click to toggle source
# File lib/maitredee/cli/runner.rb, line 101 def require_workers(required) return unless required if File.directory?(required) Dir[File.join(required, '**', '*.rb')].each(&method(:require)) else require required end end
start()
click to toggle source
# File lib/maitredee/cli/runner.rb, line 29 def start cli_opts = options.to_h.symbolize_keys say '[DEPRECATED] Please use --config instead of --config-file', :yellow if cli_opts[:config_file] cli_opts[:config_file] = cli_opts.delete(:config) if cli_opts[:config] config_file_opts = {} if cli_opts[:config_file] path = cli_opts.delete(:config_file) fail ArgumentError, "The supplied config file #{path} does not exist" unless File.exist?(path) config_file_opts = YAML.load(ERB.new(IO.read(path)).result) config_file_opts.deep_symbolize_keys! end opts = config_file_opts.merge(cli_opts) opts[:subscribers] = [] opts[:subscribers] += cli_opts[:subscribers] if cli_opts[:subscribers] opts[:subscribers] += config_file_opts[:subscribers] if config_file_opts[:subscribers] opts[:subscribers].uniq! if opts[:rails] opts.delete(:rails) load_rails end if opts[:require] require_workers(opts.delete(:require)) end if opts[:subscribers] opts[:queues] = opts.delete(:subscribers).map(&:constantize).map(&:queue_resource_name) end fail_task "You should set a logfile if you're going to daemonize" if opts[:daemon] && opts[:logfile].nil? file = Tempfile.new(['maitredee-to-shoryuken', '.yml']) file.write(YAML.dump(opts)) file.flush Shoryuken::Runner.instance.run(config_file: file.path) end
version()
click to toggle source
# File lib/maitredee/cli/runner.rb, line 75 def version say "Maitredee #{Maitredee::VERSION}" say "Shoryuken #{Shoryuken::VERSION}" end