Module: RightSpeed::Processor

Defined in:
lib/right_speed/processor.rb

Defined Under Namespace

Classes: AcceptProcessor, Base, FairProcessor, RoundRobinProcessor

Class Method Summary collapse

Class Method Details

.build_app(ru) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/right_speed/processor.rb', line 33

def self.build_app(ru)
  app = Rack::Builder.parse_file(ru)
  if app.respond_to?(:call)
    app
  elsif app.is_a?(Array) && app[0].respond_to?(:call)
    # Rack::Builder returns [app, options] but options will be deprecated
    app[0]
  else
    raise "Failed to build Rack app from #{ru}: #{app}"
  end
end

.setup(app:, worker_type:, workers:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/right_speed/processor.rb', line 12

def self.setup(app:, worker_type:, workers:)
  app = if app.respond_to?(:call)
          app
        elsif app.is_a?(String) # rackup config path
          build_app(app)
        else
          raise "Unexpected app #{app}"
        end
  handler = Ractor.make_shareable(Handler.new(app))
  case worker_type
  when :roundrobin
    RoundRobinProcessor.new(workers, handler)
  when :fair
    FairProcessor.new(workers, handler)
  when :accept
    AcceptProcessor.new(workers, handler)
  else
    raise "Unknown worker type #{worker_type}"
  end
end