Class: Protein::Server
- Inherits:
-
Object
- Object
- Protein::Server
- Defined in:
- lib/protein/server.rb
Class Method Summary collapse
- .config(config = nil) ⇒ Object
- .route(router) ⇒ Object
- .router ⇒ Object
- .service(service) ⇒ Object
- .start ⇒ Object
- .transport(transport, opts = {}) ⇒ Object
- .transport_class ⇒ Object
Class Method Details
.config(config = nil) ⇒ Object
19 20 21 22 |
# File 'lib/protein/server.rb', line 19 def config(config = nil) @config = (@config || {}).merge(config) if config @config || {} end |
.route(router) ⇒ Object
6 7 8 |
# File 'lib/protein/server.rb', line 6 def route(router) @router = Router.define(router) end |
.router ⇒ Object
15 16 17 |
# File 'lib/protein/server.rb', line 15 def router GetConst.call(@router) end |
.service(service) ⇒ Object
10 11 12 13 |
# File 'lib/protein/server.rb', line 10 def service(service) @router ||= Class.new(Router) @router.service(service) end |
.start ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/protein/server.rb', line 32 def start worker_count = config.fetch(:concurrency, 5) on_worker_boot = config[:on_worker_boot] if worker_count.is_a?(Integer) && worker_count > 1 Parallel.each(1..worker_count, in_processes: worker_count) do |worker| Protein.logger.info "Starting server #{worker}/#{worker_count} with PID #{Process.pid}" on_worker_boot.call if on_worker_boot.respond_to?(:call) transport_class.serve(router) end else transport_class.serve(router) end end |