From 10620cd7539a25899f4457a3bdc3a609bd980cdd Mon Sep 17 00:00:00 2001 From: Quentin Brossard Date: Tue, 9 Feb 2016 09:03:59 +0100 Subject: [PATCH] Switch server to puma and adapt command line - adapt command line to use pumactl - change command line options to support pumactl daemon mode with configurable pidfile - adapt cli_test.rb to the new setup - use newest rubies and jruby in travis builds --- .travis.yml | 9 +++++---- dashing.gemspec | 2 +- lib/dashing/app.rb | 13 +------------ lib/dashing/cli.rb | 13 ++++++++----- test/cli_test.rb | 26 +++++++++++++++++++------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66b5ca9a..84155ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: ruby rvm: - - 2.1.2 - - 2.0.0 - - 1.9.3 - + - 2.3.0 + - 2.2.4 + - 2.1.8 + - jruby-19mode + - jruby-9.0.4.0 script: "rake test" diff --git a/dashing.gemspec b/dashing.gemspec index 33b5b17f..80b7db27 100644 --- a/dashing.gemspec +++ b/dashing.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency('execjs', '~> 2.0.2') s.add_dependency('sinatra', '~> 1.4.4') s.add_dependency('sinatra-contrib', '~> 1.4.2') - s.add_dependency('thin', '~> 1.6.1') + s.add_dependency('puma', '~> 2.16.0') s.add_dependency('rufus-scheduler', '~> 2.0.24') s.add_dependency('thor', '> 0.18.1') s.add_dependency('sprockets', '~> 2.10.1') diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index b11352d2..52f96ab7 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -6,7 +6,6 @@ require 'sass' require 'json' require 'yaml' -require 'thin' SCHEDULER = Rufus::Scheduler.new @@ -34,7 +33,7 @@ def authenticated?(token) set :sprockets, Sprockets::Environment.new(settings.root) set :assets_prefix, '/assets' set :digest_assets, false -set server: 'thin', connections: [], history_file: 'history.yml' +set server: 'puma', connections: [], history_file: 'history.yml' set :public_folder, File.join(settings.root, 'public') set :views, File.join(settings.root, 'dashboards') set :default_dashboard, nil @@ -123,16 +122,6 @@ def authenticated?(token) end end -Thin::Server.class_eval do - def stop_with_connection_closing - Sinatra::Application.settings.connections.dup.each(&:close) - stop_without_connection_closing - end - - alias_method :stop_without_connection_closing, :stop - alias_method :stop, :stop_with_connection_closing -end - def send_event(id, body, target=nil) body[:id] = id body[:updatedAt] ||= Time.now.to_i diff --git a/lib/dashing/cli.rb b/lib/dashing/cli.rb index 4b93f892..b329e5de 100644 --- a/lib/dashing/cli.rb +++ b/lib/dashing/cli.rb @@ -57,16 +57,19 @@ def install(gist_id, *args) desc "start", "Starts the server in style!" method_option :job_path, :desc => "Specify the directory where jobs are stored" def start(*args) - port_option = args.include?('-p') ? '' : ' -p 3030' + #TODO use correct dir for pid. + daemon_pidfile = args.include?('-d') && !args.any? { |val| /^--pidfile/ =~ val } ? '--pidfile ./puma.pid' : '' args = args.join(' ') - command = "bundle exec thin -R config.ru start#{port_option} #{args}" + command = "bundle exec pumactl start #{args} #{daemon_pidfile}" command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] run_command(command) end - desc "stop", "Stops the thin server" - def stop - command = "bundle exec thin stop" + desc "stop", "Stops the puma server (daemon mode only)" + def stop(*args) + args = args.join(' ') + daemon_pidfile = !args.include?('--pidfile') ? '--pidfile ./puma.pid' : args + command = "bundle exec pumactl #{daemon_pidfile} stop" run_command(command) end diff --git a/test/cli_test.rb b/test/cli_test.rb index 4d822969..b24ea51e 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -101,14 +101,26 @@ def test_install_task_warns_when_gist_not_found assert_includes output, 'Could not find gist at ' end - def test_start_task_starts_thin_with_default_port - command = 'bundle exec thin -R config.ru start -p 3030 ' + def test_start_task_starts_puma_with_default_port + command = 'bundle exec pumactl start ' @cli.stubs(:run_command).with(command).once @cli.start end - def test_start_task_starts_thin_with_specified_port - command = 'bundle exec thin -R config.ru start -p 2020' + def test_start_task_starts_puma_in_daemon_mode + command = 'bundle exec pumactl start -d --pidfile ./puma.pid' + @cli.stubs(:run_command).with(command).once + @cli.start('-d') + end + + def test_start_task_starts_puma_in_daemon_mode_with_custom_pidfile + command = 'bundle exec pumactl start -d --pidfile /tmp/pids/puma.pid ' + @cli.stubs(:run_command).with(command).once + @cli.start('-d', '--pidfile /tmp/pids/puma.pid') + end + + def test_start_task_starts_puma_with_specified_port + command = 'bundle exec pumactl start -p 2020 ' @cli.stubs(:run_command).with(command).once @cli.start('-p', '2020') end @@ -116,7 +128,7 @@ def test_start_task_starts_thin_with_specified_port def test_start_task_supports_job_path_option commands = [ 'export JOB_PATH=other_spot; ', - 'bundle exec thin -R config.ru start -p 3030 ' + 'bundle exec pumactl start ' ] @cli.stubs(:options).returns(job_path: 'other_spot') @@ -124,8 +136,8 @@ def test_start_task_supports_job_path_option @cli.start end - def test_stop_task_stops_thin_server - @cli.stubs(:run_command).with('bundle exec thin stop') + def test_stop_task_stops_puma_server + @cli.stubs(:run_command).with('bundle exec pumactl --pidfile ./puma.pid stop') @cli.stop end