retention

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultEraseInterval is default interval for next iteration
	// of erasing old data.
	DefaultEraseInterval = 24 * time.Hour
	// DefaultRetentionWindow is the interval of days that will
	// not be deleted. All data older than current number of days
	// will be deleted.
	DefaultRetentionWindow = 60
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Interval for the next iteratin of erasing old data.
	//
	// Optional. By default: DefaultEraseInterval.
	EraseInterval time.Duration
	// The data older then current number of days will be deleted
	// at the next iteration.
	//
	// Optional. Default: DefaultRetentionWindow.
	RetentionWindowDays int
	// Callback to handle an error if one occurs while erasing data.
	//
	// Optional.
	ErrorCallback func(err error)
}

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

Policy is a structure that deletes data older than specified interval. This is useful if we do not need to keep all old data all the time.

func NewPolicy

func NewPolicy(conn *sql.DB, tableName string, config ...Config) *Policy

NewPolicy creates new Policy to erasing old data at the specified table. The specified table must contain a `created_at` field otherwise the structure will not work.

Arguments.

conn - connection to the database we need to interact with.
tableName - the name of the table in which we need to save the data window only.
config - optional configuration of retention policy.

func (*Policy) Start

func (p *Policy) Start(ctx context.Context)

Start retention process. The function is blocking the main loop. Close the context to stop erasing process.

Jump to

Keyboard shortcuts

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