Skip to content

Commit

Permalink
fix(transform): don't write to out streams when nil, use updated prev…
Browse files Browse the repository at this point in the history
…iew.Create

new preview create lets us make previews & still read body data downstream
  • Loading branch information
b5 committed Jan 28, 2021
1 parent 552f07b commit 28651cb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/qri-io/dag v0.2.2-0.20201208212257-ae00241c4b48
github.com/qri-io/dataset v0.2.1-0.20210126031523-f94fd2290107
github.com/qri-io/dataset v0.2.1-0.20210128201320-3b1209495e96
github.com/qri-io/deepdiff v0.2.1-0.20200807143746-d02d9f531f5b
github.com/qri-io/didmod v0.0.0-20201123165422-8b2e224c993a
github.com/qri-io/doggos v0.1.0
Expand Down
8 changes: 4 additions & 4 deletions lib/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,12 @@ func (m *DatasetMethods) Save(p *SaveParams, res *dataset.Dataset) error {
// allocate an ID for the transform, for now just log the events it produces
runID := transform.NewRunID()
m.inst.bus.SubscribeID(func(ctx context.Context, e event.Event) error {
when := time.Unix(e.Timestamp/1000000000, e.Timestamp%1000000000)
log.Infof("[%s] event %s: %s", when, e.Type, e.Payload)
if e.Type == event.ETTransformPrint {
if msg, ok := e.Payload.(event.TransformMessage); ok {
io.WriteString(scriptOut, msg.Msg)
io.WriteString(scriptOut, "\n")
if p.ScriptOutput != nil {
io.WriteString(scriptOut, msg.Msg)
io.WriteString(scriptOut, "\n")
}
}
}
return nil
Expand Down
6 changes: 4 additions & 2 deletions lib/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ func (m *TransformMethods) Apply(p *ApplyParams, res *ApplyResult) error {
log.Debugw("apply transform event", "type", e.Type, "payload", e.Payload)
if e.Type == event.ETTransformPrint {
if msg, ok := e.Payload.(event.TransformMessage); ok {
io.WriteString(p.ScriptOutput, msg.Msg)
io.WriteString(p.ScriptOutput, "\n")
if p.ScriptOutput != nil {
io.WriteString(p.ScriptOutput, msg.Msg)
io.WriteString(p.ScriptOutput, "\n")
}
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion remote/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (rp LocalPreviews) Preview(ctx context.Context, _, refStr string) (*dataset
return nil, err
}

return preview.CreatePreview(ctx, ds)
return preview.Create(ctx, ds)
}

// PreviewComponent gets a component for a reference & component name
Expand Down
2 changes: 1 addition & 1 deletion transform/startf/exec_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (r *StepRunner) callTransformFunc(ctx context.Context, thread *starlark.Thr
}

if r.eventsCh != nil {
pview, err := preview.CreatePreview(ctx, ds)
pview, err := preview.Create(ctx, ds)
if err != nil {
return err
}
Expand Down

0 comments on commit 28651cb

Please sign in to comment.