rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 5521513c2ac5510719af6b2ea907c5ff31dc015a 1277 bytes (raw)
$ git show v0.3.0:lib/rainbows/http_server.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
# -*- encoding: binary -*-
require 'rainbows'
module Rainbows

  class HttpServer < ::Unicorn::HttpServer
    include Rainbows

    @@instance = nil

    class << self
      def setup(block)
        @@instance.instance_eval(&block)
      end
    end

    def initialize(app, options)
      @@instance = self
      rv = super(app, options)
      defined?(@use) or use(:Base)
      @worker_connections ||= MODEL_WORKER_CONNECTIONS[@use]
    end

    def use(*args)
      model = args.shift or return @use
      mod = begin
        Rainbows.const_get(model)
      rescue NameError
        raise ArgumentError, "concurrency model #{model.inspect} not supported"
      end

      Module === mod or
        raise ArgumentError, "concurrency model #{model.inspect} not supported"
      extend(mod)
      Const::RACK_DEFAULTS['rainbows.model'] = @use = model
      Const::RACK_DEFAULTS['rack.multithread'] = !!(/Thread/ =~ model.to_s)
      Const::RACK_DEFAULTS['rainbows.autochunk'] = (model.to_s == "Rev")
    end

    def worker_connections(*args)
      return @worker_connections if args.empty?
      nr = args.first
      (Integer === nr && nr > 0) or
        raise ArgumentError, "worker_connections must be a positive Integer"
      @worker_connections = nr
    end

  end

end

git clone https://yhbt.net/rainbows.git