Documentation
¶
Overview ¶
Package exit implements a keepalive.Listener that shuts the process down after a period of inactivity — the "inactivity-detection (we kill)" listener anticipated by the keepalive package doc.
It inverts the sprites lease model for providers where compute stops when the main process exits (Fly Machines with restart policy "no"): instead of renewing a lease while active, clank-host exits cleanly once idle and the provider's edge restarts it on the next request.
"Active" is the union of three signals:
- backend events (the Tick's lastActivity, fed by agent sessions)
- HTTP traffic (every request through TrackHTTP refreshes the clock)
- in-flight requests (open SSE streams, tunnel bridges — any request still being served vetoes exit regardless of timestamps)
Process start counts as activity so a machine woken for a single request always gets a full idle window to serve it.
Index ¶
Constants ¶
const DefaultIdleThreshold = 3 * time.Minute
DefaultIdleThreshold matches the sprites listener's window: the host shuts down ~3 minutes after the last sign of life.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener triggers Options.Shutdown when idle. Construct via New, wrap the host's HTTP handler with TrackHTTP, and register with the keepalive Loop like any other Listener.
func New ¶
New constructs a Listener. Panics on a missing Shutdown — a nil trigger would silently disable the provider's only stop mechanism.
func (*Listener) Close ¶
Close implements keepalive.Listener. Nothing to release — the process is already on its way down when this runs.
type Options ¶
type Options struct {
Shutdown func()
IdleThreshold time.Duration // zero → DefaultIdleThreshold
Log *log.Logger // nil → log.Default()
// Now overrides the clock. Tests inject a controllable clock to
// drive the decision table without sleeping. Nil means time.Now.
Now func() time.Time
}
Options configures the Listener. Shutdown is required — it must initiate a graceful process shutdown (production sends SIGTERM to self so the server drains through the normal signal path).