diff --git a/lib/shoryuken/cli.rb b/lib/shoryuken/cli.rb index 7a53d1a1..fb48f698 100644 --- a/lib/shoryuken/cli.rb +++ b/lib/shoryuken/cli.rb @@ -43,7 +43,7 @@ def run(args) @launcher = Shoryuken::Launcher.new - if callback = Shoryuken.start_callback + if (callback = Shoryuken.start_callback) logger.info { 'Calling Shoryuken.on_start block' } callback.call end @@ -103,11 +103,9 @@ def daemonize(options) end def write_pid(options) - if (path = options[:pidfile]) - File.open(path, 'w') do |f| - f.puts Process.pid - end - end + return unless (path = options[:pidfile]) + + File.open(path, 'w') { |f| f.puts(Process.pid) } end def parse_cli_args(argv) diff --git a/lib/shoryuken/launcher.rb b/lib/shoryuken/launcher.rb index 6027f1c0..8be1b021 100644 --- a/lib/shoryuken/launcher.rb +++ b/lib/shoryuken/launcher.rb @@ -7,23 +7,18 @@ def initialize raise(ArgumentError, "Concurrency value #{count} is invalid, it needs to be a positive number") unless count > 0 - @managers = Array.new(count) do - Shoryuken::Manager.new(1, - Shoryuken::Fetcher.new, - Shoryuken.options[:polling_strategy].new(Shoryuken.queues)) - end + @manager = Shoryuken::Manager.new(count, + Shoryuken::Fetcher.new, + Shoryuken.options[:polling_strategy].new(Shoryuken.queues)) end def stop(options = {}) - @managers.map do |manager| - Thread.new { manager.stop(shutdown: !!options[:shutdown], timeout: Shoryuken.options[:timeout]) } - end.each(&:join) + @manager.stop(shutdown: !options[:shutdown].nil?, + timeout: Shoryuken.options[:timeout]) end def run - @managers.map do |manager| - Thread.new { manager.start } - end.each(&:join) + @manager.start end end end