Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrStarted is returned when trying to start an already started Service. ErrStarted = errors.New("service started") // ErrStopped is returned when trying to stop a Service that is not started. ErrStopped = errors.New("service stopped") )
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a Snapshot cleanup service which deletes Snapshots that exceed a given age.
func NewService ¶
NewService returns a new Service which periodically deletes old Snapshots every `every` Duration. Snapshots that exceed the given maxAge will be deleted by the Service.
Example:
// Every day, delete Snapshots that are older than a week. var store snapshot.Store svc := cleanup.NewService(24*time.Hour, 7*24*time.Hour) errs, err := svc.Start(store) // handle err for err := range errs { // handle async err }
func (*Service) Start ¶
Start starts the cleanup service and returns a channel of asynchronous errors that occur during a cleanup. Callers of Start must receive from the returned error channel; otherwise the Service will block when an error occurs. The returned error channel is closed when the Service is stopped.
Start returns a nil channel and ErrStarted if the Service has been started already.
Example:
var store snapshot.Store svc := cleanup.NewService(24*time.Hour, 7*24*time.Hour) errs, err := svc.Start(store) // handle err go func() { for err := range errs { // handle async err } }()
func (*Service) Stop ¶
Stop stops the Service. Should ctx be canceled before Stop completes, ctx.Err() is returned. If the Service has already been started, Stop returns ErrStopped.
Example:
svc := cleanup.NewService(24*time.Hour, 7*24*time.Hour) errs, err := svc.Start() // handle err & async errs if err = svc.Stop(context.TODO()); err != nil { // handle err }