Help us shape the future of Go! Take the 2026 Go Developer Survey

sleep

package
v0.4.0-beta.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sleep decides when an idle deployment should be stopped. How a deployment shows activity is an Activity; the controller takes the most recent activity any of them reports, so signals can be added or replaced without touching the decision.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity interface {
	LastActive(ctx context.Context, deployment string, now time.Time) (time.Time, error)
}

Activity reports the last time a deployment was seen doing work. A zero time means this signal has no evidence either way.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func NewController

func NewController(now time.Time, activities ...Activity) *Controller

NewController starts the idle clock for every deployment at now, so a restarted agent never puts deployments to sleep on its first pass.

func (*Controller) AwakeSince

func (c *Controller) AwakeSince(name string) time.Time

AwakeSince returns when the deployment was last noted awake, or zero.

func (*Controller) Due

func (c *Controller) Due(ctx context.Context, targets []Target, now time.Time) []string

Due returns the targets that have been idle for at least their IdleFor.

func (*Controller) NoteAwake

func (c *Controller) NoteAwake(name string, at time.Time)

NoteAwake records that a deployment was just started, which counts as activity.

type NetworkActivity

type NetworkActivity struct {
	ReceivedBytes func(ctx context.Context, deployment string) (uint64, error)
	Threshold     uint64
	// contains filtered or unexported fields
}

NetworkActivity treats a rise in a deployment's received bytes between two observations as activity. Threshold absorbs background chatter such as DNS and health probes.

func (*NetworkActivity) LastActive

func (n *NetworkActivity) LastActive(ctx context.Context, deployment string, now time.Time) (time.Time, error)

type Target

type Target struct {
	Name    string
	IdleFor time.Duration
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL