cleaner

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cleaner contains handler to clean completed task N time ago.

Index

Constants

This section is empty.

Variables

View Source
var HandlerCleanerTask = "_cleaner"

HandlerCleanerTask name of the cleaner task name.

Functions

This section is empty.

Types

type Cleaner

type Cleaner struct {
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

Cleaner contains clean handler and self repeated callback.

func New

func New(
	ctx context.Context,
	errLog io.Writer,
	st Storage,
	tm *tmanager.TaskManager,
	config *Config,
) (*Cleaner, error)

New creates new cleaner task in the task manager and returns Cleaner with logger and config. Feel free to pass nil in config.

func (*Cleaner) CallbackTask

func (c *Cleaner) CallbackTask(ctx context.Context, task tmanager.Task, handlerErr error)

CallbackTask self repeated callback.

func (*Cleaner) HandleTask

func (c *Cleaner) HandleTask(ctx context.Context, _ json.RawMessage) error

HandleTask calls storage method to clean completed task older then config param.

type Config

type Config struct {
	// OlderThen task should be older than this parameter to be deleted.
	OlderThen time.Duration

	// CleanTasksPeriod cleaner of the old completed tasks will run every specified time period.
	CleanTasksPeriod time.Duration

	// HandlerNames names of the handler to be deleted.
	// If empty then cleaner will delete all old tasks.
	HandlerNames []string
}

Config configuration of the cleaner tasks.

type Storage

type Storage interface {
	// DeleteCompletedTasks delete completed tasks older then olderThen param.
	DeleteCompletedTasks(ctx context.Context, olderThen time.Time) error

	// DeleteNamedCompletedTasks delete completed tasks with special handler names
	// and completed before olderThen param.
	DeleteNamedCompletedTasks(ctx context.Context, olderThen time.Time, names ...string) error
}

Storage of the task with old tasks.

Jump to

Keyboard shortcuts

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