File: task.go

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (35 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package tasklog

import "time"

// Task is an interface which encapsulates an activity which can be logged.
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
}

// Update is a single message sent (S) from a Task at a given time (At).
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
}

// 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.
func (u *Update) Throttled(next time.Time) bool {
	return !(u.Force || u.At.After(next))
}