Documentation
¶
Overview ¶
Package inspector contains handler to inspect stucked tasks in storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
CallbackTask self repeated callback.
func (*Inspector) HandleTask ¶ added in v0.0.5
HandleTask calls storage method to clean completed task older then config param.
type LoggerInspector ¶
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
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.