role

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package role is how a controller or a runner goes about its work, wherever it is hosted: in passes.

Index

Constants

View Source
const HostMargin = 10 * time.Second

HostMargin is how long before the host's limit a pass stops taking up new work, to finish what it has in hand.

Variables

This section is empty.

Functions

func Once

func Once(ctx context.Context, until time.Time, margin time.Duration, pass Pass) (time.Time, error)

Once runs one pass for a host that calls for passes itself and kills a copy at a time it gives. The pass is told to stop taking up new work a margin before that time, or halfway to it where less than two margins are left, and nothing of it goes on after it has answered.

func OwnConfig

func OwnConfig(dir string) (string, error)

OwnConfig gives the config directory a role is to use. A serverless host unpacks its package read-only and readable by everyone, and an identity that others can read is not accepted: there the config is copied to a place of the copy's own, made its owner's alone, and that place is given. Anywhere else the config is used where it is.

func Run

func Run(ctx context.Context, interval time.Duration, now func() time.Time, report func(role string, err error), roles ...Role)

Run runs each role's passes in a loop until the context ends: a pass, then a sleep until the next thing is due or for the interval, whichever is sooner. A role is woken at once when another role in the process writes something it reads; that changes when a pass happens and never what a pass does.

report is told of each pass that failed. Such a pass has failed nothing: what was waiting is still waiting for the next one.

func Serve

func Serve(ctx context.Context, report func(role string, err error), roles ...Role) error

Serve answers the host's calls until the context ends: for each call, one pass of each role, and then the answer. Nothing of a pass goes on after it has answered.

func Serverless

func Serverless() bool

Serverless says whether the process is on a host that calls for passes itself.

func StoreFits

func StoreFits(address string) error

StoreFits refuses, on a serverless host, a store that is a directory or memory. Copies on such a host share no disk and no memory, so each would see a store of its own.

Types

type Pass

type Pass func(ctx context.Context) (next time.Time, err error)

A Pass looks at the store, does everything that is owed, and stops. It says when the next thing is due, if it knows of one. Nothing is carried in memory from one pass to the next.

type Role

type Role struct {
	Name   string
	Pass   Pass
	Notice <-chan struct{}
}

A Role is one role of a process: its pass, and the notice its store gives when something it reads is written by this same process.

Jump to

Keyboard shortcuts

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