inspector

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 inspector contains handler to inspect stucked tasks in storage.

Index

Constants

This section is empty.

Variables

View Source
var HandlerInspectorTask = "_inspector"

HandlerInspectorTask names of the inspector handler in the task manager.

Functions

This section is empty.

Types

type Config

type Config struct {
	// StuckedInWorkAgo task will be considered stucked if
	// it was taken to work more than an StuckedInWorkAgo ago.
	StuckedInWorkAgo time.Duration

	// CheckTasksPeriod inspector of the problem tasks
	// will run every specified time period.
	CheckTasksPeriod time.Duration
}

Config configuration of the inspector tasks.

type Inspector

type Inspector struct {
	Config *Config
	Logger *log.Logger

	OnInspectedTasks OnInspectedTasks
	// contains filtered or unexported fields
}

Inspector contains task manager handlers to check stucked and failed tasks.

func New

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

New creates new Inspector. Takes storage and user handlers on inspected task. Feel free to pass nil in config.

func (*Inspector) CallbackTask added in v0.0.5

func (insp *Inspector) CallbackTask(ctx context.Context, task tmanager.Task, handlerErr error)

CallbackTask self repeated callback.

func (*Inspector) HandleTask added in v0.0.5

func (insp *Inspector) HandleTask(ctx context.Context, _ json.RawMessage) error

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

type LoggerInspector

type LoggerInspector struct {
	Logger *log.Logger
}

LoggerInspector inspector with logger just write about stucked and failed tasks.

func NewLoggerInspector

func NewLoggerInspector(logWriter io.Writer) *LoggerInspector

NewLoggerInspector returns new inspector with logger.

li := inspector.NewLoggerInspector(log)
insp, err := inspector.New(..., li.OnInspectedTasks, nil)

func (*LoggerInspector) OnInspectedTasks added in v0.0.5

func (li *LoggerInspector) OnInspectedTasks(_ context.Context, stuckedTasks, failedTasks []Task)

OnInspectedTasks inspector callback prints count of the stucked and failed tasks.

type OnInspectedTasks added in v0.0.5

type OnInspectedTasks func(ctx context.Context, stuckedTasks, failedTasks []Task)

OnInspectedTasks user actions on inspected tasks. Takes task manager context and lists of the stucked and failed tasks.

type Storage

type Storage interface {
	// GetStuckedTasks returns stucked tasks.
	// Stuck task it is task without error and taked in work before inWorkBefore.
	// Returns empty slcie when storage can't found stucked tasks.
	GetStuckedTasks(ctx context.Context, inWorkBefore time.Time) ([]Task, error)

	// GetFailedTasks returns failed tasks.
	// Failed task it is undone task with error.
	// Returns empty slcie when storage can't found failed tasks.
	GetFailedTasks(ctx context.Context) ([]Task, error)
}

Storage of the task with stucked and failed tasks.

type Task

type Task interface {
	tmanager.Task

	// GetError returns text of the task stored in the Storage.
	GetError() string
}

Task is the task type extension to get the error text from task.

Jump to

Keyboard shortcuts

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