Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from compose/13-optionalapi
Browse files Browse the repository at this point in the history
This makes the api in the config.yaml optional
  • Loading branch information
nstott committed Dec 19, 2014
2 parents 25473d8 + ec9e36c commit 664bf78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
30 changes: 24 additions & 6 deletions cmd/transporter/javascript_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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().
Expand All @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions test/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 664bf78

Please sign in to comment.