tasklog

package
v2.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLoggingThrottle = 200 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ListTask

type ListTask struct {
	// contains filtered or unexported fields
}

ListTask is a Task implementation that logs all updates in a list where each entry is line-delimited.

For example:

entry #1
entry #2
msg: ..., done

func NewListTask

func NewListTask(msg string) *ListTask

NewListTask instantiates a new *ListTask instance with the given message.

func (*ListTask) Complete

func (l *ListTask) Complete()

func (*ListTask) Entry

func (l *ListTask) Entry(update string)

Entry logs a line-delimited task entry.

func (*ListTask) Throttled

func (l *ListTask) Throttled() bool

Throttled implements the Task.Throttled function and ensures that all log updates are printed to the sink.

func (*ListTask) Updates

func (l *ListTask) Updates() <-chan *Update

Updates implements the Task.Updates function and returns a channel of updates to log to the sink.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger logs a series of tasks to an io.Writer, processing each task in order until completion .

func NewLogger

func NewLogger(sink io.Writer) *Logger

NewLogger retuns a new *Logger instance that logs to "sink" and uses the current terminal width as the width of the line.

func (*Logger) Close

func (l *Logger) Close()

Close closes the queue and does not allow new Tasks to be `enqueue()`'d. It waits until the currently running Task has completed.

func (*Logger) Enqueue

func (l *Logger) Enqueue(ts ...Task)

Enqueue enqueues the given Tasks "ts".

func (*Logger) List

func (l *Logger) List(msg string) *ListTask

List creates and enqueues a new *ListTask.

func (*Logger) Percentage

func (l *Logger) Percentage(msg string, total uint64) *PercentageTask

Percentage creates and enqueues a new *PercentageTask.

func (*Logger) Simple

func (l *Logger) Simple() *SimpleTask

List creates and enqueues a new *SimpleTask.

func (*Logger) Waiter

func (l *Logger) Waiter(msg string) *WaitingTask

Waitier creates and enqueues a new *WaitingTask.

type PercentageTask

type PercentageTask struct {
	// contains filtered or unexported fields
}

PercentageTask is a task that is performed against a known number of elements.

func NewPercentageTask

func NewPercentageTask(msg string, total uint64) *PercentageTask

func (*PercentageTask) Count

func (c *PercentageTask) Count(n uint64) (new uint64)

Count indicates that work has been completed against "n" number of elements, marking the task as complete if the total "n" given to all invocations of this method is equal to total.

Count returns the new total number of (atomically managed) elements that have been completed.

func (*PercentageTask) Entry

func (t *PercentageTask) Entry(update string)

Entry logs a line-delimited task entry.

func (*PercentageTask) Throttled

func (c *PercentageTask) Throttled() bool

Throttled implements Task.Throttled and returns true, indicating that this task is throttled.

func (*PercentageTask) Updates

func (c *PercentageTask) Updates() <-chan *Update

Updates implements Task.Updates and returns a channel which is written to when the state of this task changes, and closed when the task is completed. has been completed.

type SimpleTask

type SimpleTask struct {
	// contains filtered or unexported fields
}

SimpleTask is in an implementation of tasklog.Task which prints out messages verbatim.

func NewSimpleTask

func NewSimpleTask() *SimpleTask

NewSimpleTask returns a new *SimpleTask instance.

func (*SimpleTask) Complete

func (s *SimpleTask) Complete()

Complete notes that the task is completed by closing the Updates channel and yields the logger to the next Task. Complete blocks until the *tasklog.Logger has acknowledged completion of this task.

func (*SimpleTask) Log

func (s *SimpleTask) Log(str string)

Log logs a string with no formatting verbs.

func (*SimpleTask) Logf

func (s *SimpleTask) Logf(str string, vals ...interface{})

Logf logs some formatted string, which is interpreted according to the rules defined in package "fmt".

func (*SimpleTask) OnComplete

func (s *SimpleTask) OnComplete()

OnComplete implements an interface which receives a call to this method when the *tasklog.Logger has finished processing this task, but before it has accepted new tasks.

func (*SimpleTask) Throttled

func (s *SimpleTask) Throttled() bool

Throttled implements Task.Throttled and returns false, indicating that this task is not throttled.

func (*SimpleTask) Updates

func (s *SimpleTask) Updates() <-chan *Update

Updates implements Task.Updates and returns a channel of updates which is closed when Complete() is called.

type Task

type Task interface {
	// Updates returns a channel which is written to with the current state
	// of the Task when an update is present. It is closed when the task is
	// complete.
	Updates() <-chan *Update

	// Throttled returns whether or not updates from this task should be
	// limited when being printed to a sink via *log.Logger.
	//
	// It is expected to return the same value for a given Task instance.
	Throttled() bool
}

Task is an interface which encapsulates an activity which can be logged.

type Update

type Update struct {
	// S is the message sent in this update.
	S string
	// At is the time that this update was sent.
	At time.Time

	// Force determines if this update should not be throttled.
	Force bool
}

Update is a single message sent (S) from a Task at a given time (At).

func (*Update) Throttled

func (u *Update) Throttled(next time.Time) bool

Throttled determines whether this update should be throttled, based on the given earliest time of the next update. The caller should determine how often updates should be throttled. An Update with Force=true is never throttled.

type WaitingTask

type WaitingTask struct {
	// contains filtered or unexported fields
}

WaitingTask represents a task for which the total number of items to do work is on is unknown.

func NewWaitingTask

func NewWaitingTask(msg string) *WaitingTask

NewWaitingTask returns a new *WaitingTask.

func (*WaitingTask) Complete

func (w *WaitingTask) Complete()

Complete marks the task as completed.

func (*WaitingTask) Throttled

func (w *WaitingTask) Throttled() bool

Throttled implements Task.Throttled and returns true, indicating that this task is Throttled.

func (*WaitingTask) Updates

func (w *WaitingTask) Updates() <-chan *Update

Done implements Task.Done and returns a channel which is closed when Complete() is called.

Jump to

Keyboard shortcuts

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