Class: GrpcKit::Session::DrainController

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/session/drain_controller.rb

Defined Under Namespace

Modules: Status

Instance Method Summary collapse

Constructor Details

#initialize(draining_time = 5) ⇒ DrainController

Returns a new instance of DrainController.



17
18
19
20
# File 'lib/grpc_kit/session/drain_controller.rb', line 17

def initialize(draining_time = 5)
  @draining_time = draining_time
  @status = Status::NOT_START
end

Instance Method Details

#next(session) ⇒ void

This method returns an undefined value.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/grpc_kit/session/drain_controller.rb', line 38

def next(session)
  case @status
  when Status::NOT_START
    # next_step
  when Status::STARTED
    session.submit_shutdown
    next_step
  when Status::SENT_SHUTDOWN
    session.submit_ping
    @sent_time = Time.now.to_i
    next_step
  when Status::SENT_PING
    # skip until #recv_ping_ack is called (1RTT)
  when Status::RECV_PING_ACK
    if @sent_time && (Time.now.to_i - @sent_time) > @draining_time
      return
    end

    session.submit_goaway(session.last_proc_stream_id, DS9::NO_ERROR)
    next_step
  when Status::SENT_GOAWAY
    # session.shutdown
  end
end

#recv_ping_ackvoid

This method returns an undefined value.



31
32
33
34
35
# File 'lib/grpc_kit/session/drain_controller.rb', line 31

def recv_ping_ack
  if @status == Status::SENT_PING
    next_step
  end
end

#start_drainingObject



26
27
28
# File 'lib/grpc_kit/session/drain_controller.rb', line 26

def start_draining
  @status = Status::STARTED
end

#start_draining?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/grpc_kit/session/drain_controller.rb', line 22

def start_draining?
  @status > Status::NOT_START
end