Documentation ¶
Overview ¶
Package bg aims to manage all background jobs run on lego. This allows to keep the number of background tasks in control and drain them properly when it is time to stop a lego.
Background jobs will typically be potentially long operations, such as uploading files, sending emails or push notifications. It can also be used for services that run infinitely like heartbeat signals or stats worker.
Package bg guarantee that a dispatched job will be started even a registry is being asked to drain right after. However, there is a slim chance that Stop() is called before Start().
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDrain = errors.New("registry is draining")
ErrDrain is the error returned when a new job attempts to be started during and the registry is draining
var ErrDup = errors.New("job has already been registered")
ErrDup is the error returned when a new job has already been registered
Functions ¶
Types ¶
type Job ¶
type Job interface { Start() Stop() }
Job is a an interface to implement to be a background job
type Reg ¶
type Reg struct {
// contains filtered or unexported fields
}
Reg (registry) holds a list of running jobs
func RegFromContext ¶
RegFromContext returns a `Reg` instance associated with `ctx`, or a new `Reg` if no existing `Reg` instance could be found.