Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

spindle: emit control log lines for start and end of steps

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
a7f7a5d2 208aee68

+52 -23
+13 -3
spindle/engine/engine.go
··· 79 79 defer cancel() 80 80 81 81 for stepIdx, step := range w.Steps { 82 + // log start of step 82 83 if wfLogger != nil { 83 - ctl := wfLogger.ControlWriter(stepIdx, step) 84 - ctl.Write([]byte(step.Name())) 84 + wfLogger. 85 + ControlWriter(stepIdx, step, models.StepStatusStart). 86 + Write([]byte{0}) 85 87 } 86 88 87 89 err = eng.RunStep(ctx, wid, &w, stepIdx, allSecrets, wfLogger) 90 + 91 + // log end of step 92 + if wfLogger != nil { 93 + wfLogger. 94 + ControlWriter(stepIdx, step, models.StepStatusEnd). 95 + Write([]byte{0}) 96 + } 97 + 88 98 if err != nil { 89 99 if errors.Is(err, ErrTimedOut) { 90 100 dbErr := db.StatusTimeout(wid, n) ··· 125 115 if err := eg.Wait(); err != nil { 126 116 l.Error("failed to run one or more workflows", "err", err) 127 117 } else { 128 - l.Error("successfully ran full pipeline") 118 + l.Info("successfully ran full pipeline") 129 119 } 130 120 }
+2 -2
spindle/engines/nixery/engine.go
··· 381 381 defer logs.Close() 382 382 383 383 _, err = stdcopy.StdCopy( 384 - wfLogger.DataWriter("stdout"), 385 - wfLogger.DataWriter("stderr"), 384 + wfLogger.DataWriter(stepIdx, "stdout"), 385 + wfLogger.DataWriter(stepIdx, "stderr"), 386 386 logs.Reader, 387 387 ) 388 388 if err != nil && err != io.EOF && !errors.Is(err, context.DeadlineExceeded) {
+14 -10
spindle/models/logger.go
··· 37 37 return l.file.Close() 38 38 } 39 39 40 - func (l *WorkflowLogger) DataWriter(stream string) io.Writer { 40 + func (l *WorkflowLogger) DataWriter(idx int, stream string) io.Writer { 41 41 return &dataWriter{ 42 42 logger: l, 43 + idx: idx, 43 44 stream: stream, 44 45 } 45 46 } 46 47 47 - func (l *WorkflowLogger) ControlWriter(idx int, step Step) io.Writer { 48 + func (l *WorkflowLogger) ControlWriter(idx int, step Step, stepStatus StepStatus) io.Writer { 48 49 return &controlWriter{ 49 - logger: l, 50 - idx: idx, 51 - step: step, 50 + logger: l, 51 + idx: idx, 52 + step: step, 53 + stepStatus: stepStatus, 52 54 } 53 55 } 54 56 55 57 type dataWriter struct { 56 58 logger *WorkflowLogger 59 + idx int 57 60 stream string 58 61 } 59 62 60 63 func (w *dataWriter) Write(p []byte) (int, error) { 61 64 line := strings.TrimRight(string(p), "\r\n") 62 - entry := NewDataLogLine(line, w.stream) 65 + entry := NewDataLogLine(w.idx, line, w.stream) 63 66 if err := w.logger.encoder.Encode(entry); err != nil { 64 67 return 0, err 65 68 } ··· 70 67 } 71 68 72 69 type controlWriter struct { 73 - logger *WorkflowLogger 74 - idx int 75 - step Step 70 + logger *WorkflowLogger 71 + idx int 72 + step Step 73 + stepStatus StepStatus 76 74 } 77 75 78 76 func (w *controlWriter) Write(_ []byte) (int, error) { 79 - entry := NewControlLogLine(w.idx, w.step) 77 + entry := NewControlLogLine(w.idx, w.step, w.stepStatus) 80 78 if err := w.logger.encoder.Encode(entry); err != nil { 81 79 return 0, err 82 80 }
+23 -8
spindle/models/models.go
··· 4 4 "fmt" 5 5 "regexp" 6 6 "slices" 7 + "time" 7 8 8 9 "tangled.org/core/api/tangled" 9 10 ··· 77 76 var ( 78 77 // step log data 79 78 LogKindData LogKind = "data" 80 - // indicates start/end of a step 79 + // indicates status of a step 81 80 LogKindControl LogKind = "control" 82 81 ) 83 82 83 + // step status indicator in control log lines 84 + type StepStatus string 85 + 86 + var ( 87 + StepStatusStart StepStatus = "start" 88 + StepStatusEnd StepStatus = "end" 89 + ) 90 + 84 91 type LogLine struct { 85 - Kind LogKind `json:"kind"` 86 - Content string `json:"content"` 92 + Kind LogKind `json:"kind"` 93 + Content string `json:"content"` 94 + Time time.Time `json:"time"` 95 + StepId int `json:"step_id"` 87 96 88 97 // fields if kind is "data" 89 98 Stream string `json:"stream,omitempty"` 90 99 91 100 // fields if kind is "control" 92 - StepId int `json:"step_id,omitempty"` 93 - StepKind StepKind `json:"step_kind,omitempty"` 94 - StepCommand string `json:"step_command,omitempty"` 101 + StepStatus StepStatus `json:"step_status,omitempty"` 102 + StepKind StepKind `json:"step_kind,omitempty"` 103 + StepCommand string `json:"step_command,omitempty"` 95 104 } 96 105 97 - func NewDataLogLine(content, stream string) LogLine { 106 + func NewDataLogLine(idx int, content, stream string) LogLine { 98 107 return LogLine{ 99 108 Kind: LogKindData, 109 + Time: time.Now(), 100 110 Content: content, 111 + StepId: idx, 101 112 Stream: stream, 102 113 } 103 114 } 104 115 105 - func NewControlLogLine(idx int, step Step) LogLine { 116 + func NewControlLogLine(idx int, step Step, status StepStatus) LogLine { 106 117 return LogLine{ 107 118 Kind: LogKindControl, 119 + Time: time.Now(), 108 120 Content: step.Name(), 109 121 StepId: idx, 122 + StepStatus: status, 110 123 StepKind: step.Kind(), 111 124 StepCommand: step.Command(), 112 125 }