Merge branch 'githistory-log-durable-tasks' into githistory-log-list-task

This commit is contained in:
Taylor Blau 2017-06-19 16:19:39 -04:00
commit edbbe1be6a
5 changed files with 15 additions and 15 deletions

@ -193,7 +193,7 @@ func (l *Logger) consume() {
func (l *Logger) logTask(task Task) { func (l *Logger) logTask(task Task) {
defer l.wg.Done() defer l.wg.Done()
logAll := task.Durable() logAll := !task.Throttled()
var last time.Time var last time.Time
var msg string var msg string

@ -13,13 +13,13 @@ type ChanTask chan string
func (e ChanTask) Updates() <-chan string { return e } func (e ChanTask) Updates() <-chan string { return e }
func (e ChanTask) Durable() Bool { return false } func (e ChanTask) Throttled() bool { return true }
type DurableChanTask chan string type UnthrottledChanTask chan string
func (e DurableChanTask) Updates() <-chan string { return e } func (e UnthrottledChanTask) Updates() <-chan string { return e }
func (e DurableChanTask) Durable() bool { return true } func (e UnthrottledChanTask) Throttled() bool { return false }
func TestLoggerLogsTasks(t *testing.T) { func TestLoggerLogsTasks(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
@ -163,7 +163,7 @@ func TestLoggerLogsAllDurableUpdates(t *testing.T) {
close(t1) // t = 0+3ε ms, throttle is closed close(t1) // t = 0+3ε ms, throttle is closed
}() }()
l.enqueue(DurableChanTask(t1)) l.enqueue(UnthrottledChanTask(t1))
l.Close() l.Close()
assert.Equal(t, strings.Join([]string{ assert.Equal(t, strings.Join([]string{

@ -65,6 +65,6 @@ func (c *PercentageTask) Updates() <-chan string {
return c.ch return c.ch
} }
// Durable implements Task.Durable and returns false, indicating that this task // Throttled implements Task.Throttled and returns true, indicating that this
// is not durable. // task is throttled.
func (c *PercentageTask) Durable() bool { return false } func (c *PercentageTask) Throttled() bool { return true }

@ -7,9 +7,9 @@ type Task interface {
// complete. // complete.
Updates() <-chan string Updates() <-chan string
// Durable returns whether or not this task should be treated as // Throttled returns whether or not updates from this task should be
// Durable. // limited when being printed to a sink via *log.Logger.
// //
// It is expected to return the same value for a given Task instance. // It is expected to return the same value for a given Task instance.
Durable() bool Throttled() bool
} }

@ -28,6 +28,6 @@ func (w *WaitingTask) Updates() <-chan string {
return w.ch return w.ch
} }
// Durable implements Task.Durable and returns false, indicating that this task // Throttled implements Task.Throttled and returns true, indicating that this
// is not durable. // task is Throttled.
func (w *WaitingTask) Durable() bool { return false } func (w *WaitingTask) Throttled() bool { return true }