uitask

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package uitask provided management of in-process long-running tasks that are exposed to the UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	CurrentTaskID() string
	OnCancel(cancelFunc context.CancelFunc)
	ReportCounters(counters map[string]CounterValue)
	ReportProgressInfo(text string)
}

Controller allows the task to communicate with task manager and receive signals.

type CounterValue

type CounterValue struct {
	Value int64  `json:"value"`
	Units string `json:"units,omitempty"`
	Level string `json:"level"` // "", "notice", "warning" or "error"
}

CounterValue describes the counter value reported by task with optional units for presentation.

func BytesCounter

func BytesCounter(v int64) CounterValue

BytesCounter returns CounterValue for the number of bytes.

func ErrorBytesCounter

func ErrorBytesCounter(v int64) CounterValue

ErrorBytesCounter returns CounterValue for the number of bytes.

func ErrorCounter

func ErrorCounter(v int64) CounterValue

ErrorCounter returns simple numeric CounterValue without units.

func NoticeBytesCounter

func NoticeBytesCounter(v int64) CounterValue

NoticeBytesCounter returns CounterValue for the number of bytes.

func NoticeCounter

func NoticeCounter(v int64) CounterValue

NoticeCounter returns simple numeric CounterValue without units.

func SimpleCounter

func SimpleCounter(v int64) CounterValue

SimpleCounter returns simple numeric CounterValue without units.

func WarningBytesCounter

func WarningBytesCounter(v int64) CounterValue

WarningBytesCounter returns CounterValue for the number of bytes.

func WarningCounter

func WarningCounter(v int64) CounterValue

WarningCounter returns simple numeric CounterValue without units.

type Info

type Info struct {
	TaskID       string                  `json:"id"`
	StartTime    time.Time               `json:"startTime"`
	EndTime      *time.Time              `json:"endTime,omitempty"`
	Kind         string                  `json:"kind"` // Maintenance, Snapshot, Restore, etc.
	Description  string                  `json:"description"`
	Status       Status                  `json:"status"`
	ProgressInfo string                  `json:"progressInfo"`
	ErrorMessage string                  `json:"errorMessage,omitempty"`
	Counters     map[string]CounterValue `json:"counters"`
	LogLines     []LogEntry              `json:"-"`
	Error        error                   `json:"-"`
	// contains filtered or unexported fields
}

Info represents information about a task (running or finished).

type LogEntry

type LogEntry struct {
	Timestamp float64  `json:"ts"` // unix timestamp possibly with fractional seconds.
	Module    string   `json:"mod"`
	Level     LogLevel `json:"level"`
	Text      string   `json:"msg"`
}

LogEntry contains one output from a single log statement.

type LogLevel

type LogLevel int

LogLevel represents the log level associated with LogEntry.

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarning
	LogLevelError
)

supported log levels.

type Manager

type Manager struct {
	MaxFinishedTasks      int
	MaxLogMessagesPerTask int
	// contains filtered or unexported fields
}

Manager manages UI tasks.

func NewManager

func NewManager() *Manager

NewManager creates new UI Task Manager.

func (*Manager) CancelTask

func (m *Manager) CancelTask(taskID string)

CancelTask retrieves the log from the task.

func (*Manager) GetTask

func (m *Manager) GetTask(taskID string) (Info, bool)

GetTask retrieves the task info.

func (*Manager) ListTasks

func (m *Manager) ListTasks() []Info

ListTasks lists all running and some recently-finished tasks up to configured limits.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, kind, description string, task TaskFunc) error

Run executes the provided task in the current goroutine while allowing it to be externally examined and canceled.

func (*Manager) TaskLog

func (m *Manager) TaskLog(taskID string) []LogEntry

TaskLog retrieves the log from the task.

func (*Manager) TaskSummary

func (m *Manager) TaskSummary() map[Status]int

TaskSummary returns the summary (number of tasks by status).

func (*Manager) WaitForTask added in v0.10.2

func (m *Manager) WaitForTask(ctx context.Context, taskID string, maxWaitTime time.Duration) (Info, bool)

WaitForTask waits for the given task to finish running or until given amount of time elapses. If the task has not completed yet, (Info{}, false) is returned.

type Status

type Status string

Status describes the status of UI Task.

const (
	StatusRunning   Status = "RUNNING"
	StatusCanceling Status = "CANCELING"
	StatusCanceled  Status = "CANCELED"
	StatusSuccess   Status = "SUCCESS"
	StatusFailed    Status = "FAILED"
)

Supported task statuses.

func (Status) IsFinished added in v0.9.0

func (s Status) IsFinished() bool

IsFinished returns true if the given status is finished.

type TaskFunc

type TaskFunc func(ctx context.Context, ctrl Controller) error

TaskFunc represents a task function.

Jump to

Keyboard shortcuts

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