Documentation
¶
Overview ¶
Package orphan stops apps none of whose owners is active, and tells administrators (R-407 – R-409).
The pass runs on the leader. It is woken when who owns an app may have changed — migration 79's triggers notify state.AppOwnersChannel when an account is suspended or deleted, an Owner grant is added or removed — so an app stops when its last owner goes, and it also runs on a schedule in case a notification was lost.
Each pass, in order:
- Apps that have an active owner again are unmarked, so losing that owner is a new orphaning. A stop it made stays until somebody starts the app.
- Apps newly without an active owner are marked, and stopped in the same write when host policy says to (stop_orphaned_apps, on by default).
- Administrators are told of every marked app they have not been told of, in one notice.
Nothing here starts an app. Starting one clears the stop (migration 79) and leaves the mark, so an administrator who starts an orphaned app keeps it running.
Index ¶
Constants ¶
const DefaultEvery = 5 * time.Minute
DefaultEvery is how often the pass runs when nothing wakes it. A notification is how an app is stopped at once; this is for one lost while the leader was not listening.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Listener ¶
type Listener interface {
Listen(ctx context.Context, channel string, changed func(payload string), connected func(bool))
}
Listener calls changed for each notification on a channel until ctx ends, and connected with whether it is listening. *state.DB is one.
type Notifier ¶
type Notifier interface {
Notify(ctx context.Context, n api.Notification) error
}
Notifier tells people things. subscription.Router is one.
type Pass ¶
type Pass struct {
Store Store
Policy PolicyLoader
// Notifier, Auditor and Changes are optional. Production wires all
// three: R-409 is a promise that administrators hear of every orphaned
// app, and Changes is what makes a stop immediate.
Notifier Notifier
Auditor Auditor
Changes Listener
Logger *zap.Logger
// Every is how often Run runs a pass with nothing to wake it. Zero is
// DefaultEvery.
Every time.Duration
}
Pass is the orphan job.
type PolicyLoader ¶
PolicyLoader reads host policy.
type Store ¶
type Store interface {
ClearOwned(ctx context.Context) ([]string, error)
NewlyOrphaned(ctx context.Context) ([]state.OrphanApp, error)
MarkOrphaned(ctx context.Context, appID string, stop bool) (marked, stopped bool, err error)
Unannounced(ctx context.Context) ([]state.OrphanApp, error)
MarkAnnounced(ctx context.Context, appIDs []string) error
Administrators(ctx context.Context) ([]string, error)
}
Store is the state the pass reads and writes. *state.Orphans is one.