ratalada 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ratalada/falcon.rb +11 -5
- data/lib/ratalada/puma.rb +3 -1
- data/lib/ratalada/version.rb +1 -1
- data/lib/ratalada.rb +42 -10
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1803a4b3f845951ed01752e1423b0c37c943b07ca1364f4b9d43e3c0a3add365
|
|
4
|
+
data.tar.gz: 104cf13b9244ecc47c975e3ea2a021db2869797bc7754fd2e745e016311780cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5705db0d6d6e6a5145f5af7882fdb3c1cbd1abca7f4ac27bcfce1ecf576ef58ce35129bab5f4e4bd27a436796c53bfb49c3b87aee7ed0126f5ac5990db74727c
|
|
7
|
+
data.tar.gz: e42d339d4e674109a13276972d6513dddf8c2ce90c6c5e6d75f50ead33c4a9dc4932e5f9ab64e33c63882970138f0dc0d5df010726ac763427e23259e6d2a617
|
data/lib/ratalada/falcon.rb
CHANGED
|
@@ -27,20 +27,26 @@ module Ratalada
|
|
|
27
27
|
middleware = ::Falcon::Server.rack_middleware(app, cache: cache)
|
|
28
28
|
|
|
29
29
|
environment = Async::Service::Environment.new(::Falcon::Environment::Server).with(
|
|
30
|
-
name:
|
|
31
|
-
url:
|
|
32
|
-
middleware:
|
|
30
|
+
name: "ratalada",
|
|
31
|
+
url: "http://#{host}:#{port}",
|
|
32
|
+
middleware: -> { middleware },
|
|
33
33
|
container_options: { count: count, restart: true },
|
|
34
34
|
# async-service >= 0.25 reads `root` in Managed::Service#preload!
|
|
35
35
|
# unconditionally (the default `preload` is `[]`, which is truthy),
|
|
36
36
|
# so an environment without one raises NoMethodError on boot.
|
|
37
|
-
root:
|
|
37
|
+
root: Dir.pwd,
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
configuration = Async::Service::Configuration.new
|
|
41
41
|
configuration.add(environment)
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
if count > 1
|
|
44
|
+
workers = " (#{count} workers)"
|
|
45
|
+
else
|
|
46
|
+
workers = ""
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
warn "ratalada: falcon listening on http://#{host}:#{port}#{workers}"
|
|
44
50
|
Async::Service::Controller.run(configuration, container_class: Async::Container.best_container_class)
|
|
45
51
|
rescue Interrupt
|
|
46
52
|
# clean shutdown
|
data/lib/ratalada/puma.rb
CHANGED
|
@@ -9,7 +9,9 @@ module Ratalada
|
|
|
9
9
|
module_function
|
|
10
10
|
|
|
11
11
|
def run(app, host:, port:, count: 1)
|
|
12
|
-
|
|
12
|
+
if count > 1
|
|
13
|
+
warn "ratalada: puma backend ignores count: (not yet implemented)"
|
|
14
|
+
end
|
|
13
15
|
server = ::Puma::Server.new(app)
|
|
14
16
|
server.add_tcp_listener(host, port)
|
|
15
17
|
warn "ratalada: puma listening on http://#{host}:#{port}"
|
data/lib/ratalada/version.rb
CHANGED
data/lib/ratalada.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rack"
|
|
4
|
+
require "dry-configurable"
|
|
4
5
|
require_relative "ratalada/version"
|
|
5
6
|
|
|
6
7
|
module Ratalada
|
|
@@ -8,6 +9,8 @@ module Ratalada
|
|
|
8
9
|
DEFAULT_PORT = Integer(ENV.fetch("PORT", "9292"))
|
|
9
10
|
DEFAULT_COUNT = Integer(ENV.fetch("COUNT", "1"))
|
|
10
11
|
|
|
12
|
+
extend Dry::Configurable
|
|
13
|
+
|
|
11
14
|
class Error < StandardError; end
|
|
12
15
|
|
|
13
16
|
class NoBackendError < Error
|
|
@@ -91,10 +94,10 @@ module Ratalada
|
|
|
91
94
|
|
|
92
95
|
def call(env)
|
|
93
96
|
request = Request.new(env)
|
|
94
|
-
|
|
95
|
-
@router.call(request)
|
|
97
|
+
begin
|
|
98
|
+
handler = @router.call(request)
|
|
96
99
|
rescue NoMatchingPatternError
|
|
97
|
-
nil
|
|
100
|
+
handler = nil
|
|
98
101
|
end
|
|
99
102
|
respond(handler, request)
|
|
100
103
|
end
|
|
@@ -133,8 +136,11 @@ module Ratalada
|
|
|
133
136
|
# count runs that many worker processes accepting from a shared socket,
|
|
134
137
|
# like node's cluster module. Each worker has its own state — anything
|
|
135
138
|
# shared (sessions, caches) needs an external store or count: 1.
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
#
|
|
140
|
+
# host:, port: and count: are written through to Ratalada.config before
|
|
141
|
+
# boot, so Server.run(port: 3000) is shorthand for configuring first.
|
|
142
|
+
def run(**options, &block)
|
|
143
|
+
Stack.new.run(**options, &block)
|
|
138
144
|
end
|
|
139
145
|
|
|
140
146
|
# The chain Server.use returns. Collects middleware until run ends it.
|
|
@@ -148,11 +154,29 @@ module Ratalada
|
|
|
148
154
|
self
|
|
149
155
|
end
|
|
150
156
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
# Every option is a Ratalada.config setting name (host, port, count);
|
|
158
|
+
# each is applied to the config verbatim — coercion and rejection of
|
|
159
|
+
# unknown names are the settings' own. Skipped entirely when no
|
|
160
|
+
# options are given so a finalized config can still boot.
|
|
161
|
+
def run(**options, &block)
|
|
162
|
+
unless block
|
|
163
|
+
raise ArgumentError, "Server.run requires a block"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
if options.any?
|
|
167
|
+
Ratalada.configure do |config|
|
|
168
|
+
options.each do |key, value|
|
|
169
|
+
config[key] = value
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
config = Ratalada.config
|
|
175
|
+
unless config.count.is_a?(Integer) && config.count.positive?
|
|
176
|
+
raise ArgumentError, "count must be a positive Integer"
|
|
177
|
+
end
|
|
154
178
|
|
|
155
|
-
Ratalada.backend.run(to_app(block), host: host, port: port, count: count)
|
|
179
|
+
Ratalada.backend.run(to_app(block), host: config.host, port: config.port, count: config.count)
|
|
156
180
|
end
|
|
157
181
|
|
|
158
182
|
# First `use` in the chain is the outermost, as in Rack::Builder.
|
|
@@ -166,4 +190,12 @@ module Ratalada
|
|
|
166
190
|
end
|
|
167
191
|
|
|
168
192
|
# The whole point is a zero-ceremony top-level DSL.
|
|
169
|
-
|
|
193
|
+
unless defined?(Server)
|
|
194
|
+
Server = Ratalada::Server
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Core settings. Contrib gems (ratalada-contrib et al.) register theirs the
|
|
198
|
+
# same way — Ratalada.setting at the bottom of their own file.
|
|
199
|
+
Ratalada.setting :host, default: Ratalada::DEFAULT_HOST
|
|
200
|
+
Ratalada.setting :port, default: Ratalada::DEFAULT_PORT, constructor: ->(value) { Integer(value) }
|
|
201
|
+
Ratalada.setting :count, default: Ratalada::DEFAULT_COUNT, constructor: ->(value) { Integer(value) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ratalada
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan K
|
|
@@ -24,19 +24,33 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '3.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: dry-configurable
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '1.4'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.4'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rspec
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '3.13'
|
|
33
47
|
type: :development
|
|
34
48
|
prerelease: false
|
|
35
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
50
|
requirements:
|
|
37
51
|
- - "~>"
|
|
38
52
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
53
|
+
version: '3.13'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: rake
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|