Skip to content
This repository was archived by the owner on Mar 7, 2018. It is now read-only.

Commit 30a5844

Browse files
committed
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
1 parent 0e3d843 commit 30a5844

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: ruby
22
rvm:
3-
- 2.1.2
4-
- 2.0.0
5-
- 1.9.3
6-
3+
- 2.3.0
4+
- 2.2.4
5+
- 2.1.8
6+
- jruby-19mode
77
script: "rake test"

lib/dashing/app.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'sass'
77
require 'json'
88
require 'yaml'
9-
require 'thin'
109

1110
SCHEDULER = Rufus::Scheduler.new
1211

@@ -34,7 +33,7 @@ def authenticated?(token)
3433
set :sprockets, Sprockets::Environment.new(settings.root)
3534
set :assets_prefix, '/assets'
3635
set :digest_assets, false
37-
set server: 'thin', connections: [], history_file: 'history.yml'
36+
set server: 'puma', connections: [], history_file: 'history.yml'
3837
set :public_folder, File.join(settings.root, 'public')
3938
set :views, File.join(settings.root, 'dashboards')
4039
set :default_dashboard, nil
@@ -123,16 +122,6 @@ def authenticated?(token)
123122
end
124123
end
125124

126-
Thin::Server.class_eval do
127-
def stop_with_connection_closing
128-
Sinatra::Application.settings.connections.dup.each(&:close)
129-
stop_without_connection_closing
130-
end
131-
132-
alias_method :stop_without_connection_closing, :stop
133-
alias_method :stop, :stop_with_connection_closing
134-
end
135-
136125
def send_event(id, body, target=nil)
137126
body[:id] = id
138127
body[:updatedAt] ||= Time.now.to_i

lib/dashing/cli.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@ def install(gist_id, *args)
5757
desc "start", "Starts the server in style!"
5858
method_option :job_path, :desc => "Specify the directory where jobs are stored"
5959
def start(*args)
60-
port_option = args.include?('-p') ? '' : ' -p 3030'
60+
#TODO use correct dir for pid.
61+
daemon_pidfile = args.include?('-d') && !args.any? { |val| /^--pidfile/ =~ val } ? '--pidfile ./puma.pid' : ''
6162
args = args.join(' ')
62-
command = "bundle exec thin -R config.ru start#{port_option} #{args}"
63+
command = "bundle exec pumactl start #{args} #{daemon_pidfile}"
6364
command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path]
6465
run_command(command)
6566
end
6667

67-
desc "stop", "Stops the thin server"
68-
def stop
69-
command = "bundle exec thin stop"
68+
desc "stop", "Stops the puma server (daemon mode only)"
69+
def stop(*args)
70+
args = args.join(' ')
71+
daemon_pidfile = !args.include?('--pidfile') ? '--pidfile ./puma.pid' : args
72+
command = "bundle exec pumactl #{daemon_pidfile} stop"
7073
run_command(command)
7174
end
7275

test/cli_test.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,43 @@ def test_install_task_warns_when_gist_not_found
101101
assert_includes output, 'Could not find gist at '
102102
end
103103

104-
def test_start_task_starts_thin_with_default_port
105-
command = 'bundle exec thin -R config.ru start -p 3030 '
104+
def test_start_task_starts_puma_with_default_port
105+
command = 'bundle exec pumactl start '
106106
@cli.stubs(:run_command).with(command).once
107107
@cli.start
108108
end
109109

110-
def test_start_task_starts_thin_with_specified_port
111-
command = 'bundle exec thin -R config.ru start -p 2020'
110+
def test_start_task_starts_puma_in_daemon_mode
111+
command = 'bundle exec pumactl start -d --pidfile ./puma.pid'
112+
@cli.stubs(:run_command).with(command).once
113+
@cli.start('-d')
114+
end
115+
116+
def test_start_task_starts_puma_in_daemon_mode_with_custom_pidfile
117+
command = 'bundle exec pumactl start -d --pidfile /tmp/pids/puma.pid '
118+
@cli.stubs(:run_command).with(command).once
119+
@cli.start('-d', '--pidfile /tmp/pids/puma.pid')
120+
end
121+
122+
def test_start_task_starts_puma_with_specified_port
123+
command = 'bundle exec pumactl start -p 2020 '
112124
@cli.stubs(:run_command).with(command).once
113125
@cli.start('-p', '2020')
114126
end
115127

116128
def test_start_task_supports_job_path_option
117129
commands = [
118130
'export JOB_PATH=other_spot; ',
119-
'bundle exec thin -R config.ru start -p 3030 '
131+
'bundle exec pumactl start '
120132
]
121133

122134
@cli.stubs(:options).returns(job_path: 'other_spot')
123135
@cli.stubs(:run_command).with(commands.join('')).once
124136
@cli.start
125137
end
126138

127-
def test_stop_task_stops_thin_server
128-
@cli.stubs(:run_command).with('bundle exec thin stop')
139+
def test_stop_task_stops_puma_server
140+
@cli.stubs(:run_command).with('bundle exec pumactl --pidfile ./puma.pid stop')
129141
@cli.stop
130142
end
131143

0 commit comments

Comments
 (0)