Documentation ¶
Overview ¶
Package uitask provided management of in-process long-running tasks that are exposed to the UI.
Index ¶
- type Controller
- type CounterValue
- func BytesCounter(v int64) CounterValue
- func ErrorBytesCounter(v int64) CounterValue
- func ErrorCounter(v int64) CounterValue
- func NoticeBytesCounter(v int64) CounterValue
- func NoticeCounter(v int64) CounterValue
- func SimpleCounter(v int64) CounterValue
- func WarningBytesCounter(v int64) CounterValue
- func WarningCounter(v int64) CounterValue
- type Info
- type LogLevel
- type Manager
- func (m *Manager) CancelTask(taskID string)
- func (m *Manager) GetTask(taskID string) (Info, bool)
- func (m *Manager) ListTasks() []Info
- func (m *Manager) Run(ctx context.Context, kind, description string, task TaskFunc) error
- func (m *Manager) TaskLog(taskID string) []json.RawMessage
- func (m *Manager) TaskSummary() map[Status]int
- func (m *Manager) WaitForTask(ctx context.Context, taskID string, maxWaitTime time.Duration) (Info, bool)
- type Status
- type TaskFunc
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 []json.RawMessage `json:"-"` Error error `json:"-"` // contains filtered or unexported fields }
Info represents information about a task (running or finished).
type Manager ¶
type Manager struct { MaxFinishedTasks int // +checklocksignore MaxLogMessagesPerTask int // +checklocksignore // contains filtered or unexported fields }
Manager manages UI tasks.
func (*Manager) CancelTask ¶
CancelTask retrieves the log from the task.
func (*Manager) ListTasks ¶
ListTasks lists all running and some recently-finished tasks up to configured limits.
func (*Manager) Run ¶
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) []json.RawMessage
TaskLog retrieves the log from the task.
func (*Manager) TaskSummary ¶
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
IsFinished returns true if the given status is finished.