~james/core

core/cilogs/logstream.go -rw-r--r-- 905 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
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
36
37
38
39
40
41
42
43
44
45
46
47
package cilogs

import (
	"context"
	"time"

	"tangled.org/core/api/org_tangled"
)

type step struct {
	id        int64
	name      string
	command   string
	lines     []string
	startTime time.Time
	endTime   time.Time
	finished  bool
}

type logDoneMsg struct {
	err error
}

type logEventMsg struct {
	ev     *org_tangled.CiSubscribePipelineLogs_Event
	events chan *org_tangled.CiSubscribePipelineLogs_Event
	done   chan error
}

type eventScheduler struct {
	ch chan *org_tangled.CiSubscribePipelineLogs_Event
}

func newEventScheduler() *eventScheduler {
	return &eventScheduler{ch: make(chan *org_tangled.CiSubscribePipelineLogs_Event, 1024)}
}

func (s *eventScheduler) AddWork(ctx context.Context, _ string, v *org_tangled.CiSubscribePipelineLogs_Event) error {
	select {
	case s.ch <- v:
		return nil
	case <-ctx.Done():
		return ctx.Err()
	}
}

func (s *eventScheduler) Shutdown() { close(s.ch) }