Class: Maitredee::CLI::Runner

Inherits:
Thor
  • Object
show all
Defined in:
lib/maitredee/cli/runner.rb

Instance Method Summary collapse

Instance Method Details

#startObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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

#versionObject



75
76
77
78
# File 'lib/maitredee/cli/runner.rb', line 75

def version
  say "Maitredee #{Maitredee::VERSION}"
  say "Shoryuken #{Shoryuken::VERSION}"
end