diff --git a/cmd/transporter/javascript_builder.go b/cmd/transporter/javascript_builder.go index e1d5efa7a..6aa5d5b81 100644 --- a/cmd/transporter/javascript_builder.go +++ b/cmd/transporter/javascript_builder.go @@ -6,6 +6,7 @@ import ( "time" "github.com/compose/transporter/pkg/adaptor" + "github.com/compose/transporter/pkg/events" "github.com/compose/transporter/pkg/transporter" "github.com/nu7hatch/gouuid" "github.com/robertkrimen/otto" @@ -194,6 +195,17 @@ func (js *JavascriptBuilder) findNode(in otto.Value) (n Node, err error) { return NewNode(sourceString, val.Type, rawMap) } +// emitter examines the config file for api information +// and returns the correct +func (js *JavascriptBuilder) emitter() events.Emitter { + if js.config.API.URI == "" { + // no URI set, return a noop emitter + return events.NewNoopEmitter() + } + + return events.NewHTTPPostEmitter(js.config.API.URI, js.config.API.Key, js.config.API.Pid) +} + // Build runs the javascript script. // each call to the Source() in the javascript creates a new JavascriptPipeline struct, // and transformers and sinks are added with calls to Transform(), and Save(). @@ -207,15 +219,21 @@ func (js *JavascriptBuilder) Build() error { return err } - for _, node := range js.nodes { - n := node.CreateTransporterNode() - - interval, err := time.ParseDuration(js.config.API.MetricsInterval) + // get the interval from the config, or else default to 60 seconds + var interval time.Duration + if js.config.API.MetricsInterval == "" { + interval = 60 * time.Second + } else { + interval, err = time.ParseDuration(js.config.API.MetricsInterval) if err != nil { - return err + return fmt.Errorf("can't parse api interval (%s)", err.Error()) } + } - pipeline, err := transporter.NewDefaultPipeline(n, js.config.API.URI, js.config.API.Key, js.config.API.Pid, interval) + // build each pipeline + for _, node := range js.nodes { + n := node.CreateTransporterNode() + pipeline, err := transporter.NewPipeline(n, js.emitter(), interval) if err != nil { return err } diff --git a/test/config.yaml b/test/config.yaml index 7383a2504..d3b44dd81 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -1,9 +1,8 @@ -api: - interval: 1s - uri: "https://app.compose.io/services/transporter/v1/events" - # uri: "http://requestb.in/13gerls1" - key: "48593282-b38d-4bf5-af58-f7327271e73d" - pid: "something-static" +# api: +# interval: 60s +# uri: "http://requestb.in/13gerls1" +# key: "48593282-b38d-4bf5-af58-f7327271e73d" +# pid: "something-static" nodes: localmongo: type: mongo