Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Switch from Thin to Puma.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Jan 15, 2014
1 parent c5be672 commit 13c6314
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ The main config objects are:
* `admins` (Array<String>) - An array of string user IDs which tell Lita which users are considered administrators. Only these users will have access to Lita's `auth` command. Default: `nil`.
* `redis` - Options for the Redis connection. See the [Redis gem](https://github.com/redis/redis-rb) documentation.
* `http` - Settings related to Lita's built-in web server.
* `host` (String) - The host the server will bind to. Default: `"0.0.0.0"`.
* `port` (Integer) - The port the server should run on. Default: `8080`.
* `debug` (Boolean) - Set to true to display the web server's logs mixed in with Lita's own logs. Default: `false`.
* `min_threads` (Integer) - The minimum number of threads the server will use. Default: `0`.
* `max_threads` (Integer) - The maximum number of threads the server will use. Default: `16`.
* `adapter` - Options for the chosen adapter. See the adapter's documentation.
* `handlers` - Handlers may choose to expose a config object here with their own options. See the handler's documentation.

Expand Down
2 changes: 1 addition & 1 deletion lib/lita.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

require "faraday"
require "multi_json"
require "puma"
require "rack"
require "redis-namespace"
require "thin"

# The main namespace for Lita. Provides a global registry of adapters and
# handlers, as well as global configuration, logger, and Redis store.
Expand Down
28 changes: 20 additions & 8 deletions lib/lita/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ class << self
# @return [Lita::Config] The default configuration.
def default_config
new.tap do |c|
c.robot = new
c.robot.name = "Lita"
c.robot.adapter = :shell
c.robot.log_level = :info
c.robot.admins = nil
load_robot_configs(c)
c.redis = new
c.http = new
c.http.port = 8080
c.http.debug = false
load_http_configs(c)
c.adapter = new
c.handlers = new
load_handler_configs(c)
Expand Down Expand Up @@ -50,6 +44,24 @@ def load_handler_configs(config)
handler.default_config(handler_config)
end
end

# Adds and populates a Config object for the built-in web server.
def load_http_configs(config)
config.http = new
config.http.host = "0.0.0.0"
config.http.port = 8080
config.http.min_threads = 0
config.http.max_threads = 16
end

# Adds and populates a Config object for the Robot.
def load_robot_configs(config)
config.robot = new
config.robot.name = "Lita"
config.robot.adapter = :shell
config.robot.log_level = :info
config.robot.admins = nil
end
end

# Sets a config key.
Expand Down
16 changes: 8 additions & 8 deletions lib/lita/robot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def set_topic(target, topic)
# @return [void]
def shut_down
trigger(:shut_down_started)
@server.stop if @server
@server.stop(true) if @server
@server_thread.join if @server_thread
@adapter.shut_down
trigger(:shut_down_complete)
Expand Down Expand Up @@ -109,14 +109,14 @@ def load_adapter

# Starts the web server.
def run_app
http_config = Lita.config.http

@server_thread = Thread.new do
@server = Thin::Server.new(
app,
Lita.config.http.port.to_i,
signals: false
)
@server.silent = true unless Lita.config.http.debug
@server.start
@server = Puma::Server.new(app)
@server.add_tcp_listener(http_config.host, http_config.port.to_i)
@server.min_threads = http_config.min_threads
@server.max_threads = http_config.max_threads
@server.run
end

@server_thread.abort_on_exception = true
Expand Down
2 changes: 1 addition & 1 deletion lita.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "bundler", ">= 1.3"
spec.add_runtime_dependency "faraday", ">= 0.8.7"
spec.add_runtime_dependency "multi_json", ">= 1.7.7"
spec.add_runtime_dependency "puma", ">= 2.7.1"
spec.add_runtime_dependency "rack", ">= 1.5.2"
spec.add_runtime_dependency "redis-namespace", ">= 1.3.0"
spec.add_runtime_dependency "thin", ">= 1.5.1"
spec.add_runtime_dependency "thor", ">= 0.18.1"

spec.add_development_dependency "rake"
Expand Down
11 changes: 3 additions & 8 deletions spec/lita/robot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@

before do
allow_any_instance_of(Lita::Adapters::Shell).to receive(:run)
allow_any_instance_of(Thin::Server).to receive(:start)
allow_any_instance_of(Puma::Server).to receive(:run)
allow_any_instance_of(Puma::Server).to receive(:add_tcp_listener)

allow(Thread).to receive(:new) do |&block|
block.call
Expand All @@ -58,13 +59,7 @@
end

it "starts the web server" do
expect_any_instance_of(Thin::Server).to receive(:start)
subject.run
end

it "doesn't silence thin if config.http.debug is true" do
Lita.config.http.debug = true
expect_any_instance_of(Thin::Server).not_to receive(:silent=)
expect_any_instance_of(Puma::Server).to receive(:run)
subject.run
end

Expand Down

0 comments on commit 13c6314

Please sign in to comment.