Class: Henitai::SlotScheduler::SlotDeadline

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/slot_scheduler/slot_deadline.rb

Overview

Seconds left before a slot is due, for the scheduler's event-wait budget.

A live slot is due at started_at + timeout. A draining slot is due at term_sent_at + drain_window instead: once SIGTERM has gone out, the only remaining question is how long to wait before escalating to SIGKILL.

Instance Method Summary collapse

Constructor Details

#initialize(drain_window:) ⇒ SlotDeadline

Returns a new instance of SlotDeadline.



11
12
13
# File 'lib/henitai/slot_scheduler/slot_deadline.rb', line 11

def initialize(drain_window:)
  @drain_window = drain_window
end

Instance Method Details

#remaining(slot, now) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/henitai/slot_scheduler/slot_deadline.rb', line 15

def remaining(slot, now)
  # Invariant: drain_draining_slots runs (and removes draining slots)
  # before the event wait, so this never observes a draining slot whose
  # SIGTERM has not been sent. Guarded defensively against a future
  # ordering change: an unsignalled draining slot is due now.
  return 0.0 if slot.draining && slot.term_sent_at_monotonic.nil?

  remaining = deadline_for(slot) - now
  remaining.positive? ? remaining : 0.0
end