Class: RightSpeed::Worker::RoundRobin

Inherits:
Base
  • Object
show all
Defined in:
lib/right_speed/worker/roundrobin.rb

Instance Attribute Summary

Attributes inherited from Base

#ractor

Instance Method Summary collapse

Methods inherited from Base

#initialize, #stop

Constructor Details

This class inherits a constructor from RightSpeed::Worker::Base

Instance Method Details

#process(conn) ⇒ Object



25
26
27
# File 'lib/right_speed/worker/roundrobin.rb', line 25

def process(conn)
  @ractor.send(conn, move: true)
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/right_speed/worker/roundrobin.rb', line 7

def run
  @ractor = Ractor.new(@id, @handler) do |id, handler|
    logger = RightSpeed.logger
    while conn = Ractor.receive
      begin
        handler.session(conn).process
        # TODO: keep-alive?
        Ractor.yield(conn, move: true) # to yield closing connections to ConnectionCloser
      rescue => e
        logger.error { "Unexpected error: #{e.message}\n" + e.backtrace.map{"\t#{_1}\n"}.join }
        # TODO: print backtrace in better way
      end
    end
    logger.info { "Worker#{id}: Finishing the Ractor" }
    Ractor.yield(:closing) # to tell the outgoing path will be closed when stopping
  end
end

#waitObject



29
30
31
# File 'lib/right_speed/worker/roundrobin.rb', line 29

def wait
  @ractor.take
end