cleanup

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewService(every, maxAge stdtime.Duration) *Service

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

func (c *Service) Start(store snapshot.Store) (<-chan error, error)

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

func (c *Service) Stop(ctx context.Context) error

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
}

Jump to

Keyboard shortcuts

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