// 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().
// the call to Transporter.add(pipeline) adds the JavascriptPipeline to the Builder's js_pipeline property
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().
the call to Transporter.add(pipeline) adds the JavascriptPipeline to the Builder's js_pipeline property
// 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 () . // the call to Transporter . add ( pipeline ) adds the JavascriptPipeline to the Builder ' s js_pipeline property
func (js *JavascriptBuilder) Build() error {
	_, err := js.vm.Run(js.script)
	if js.err != nil {
		return js.err
	}
	if err != nil {
		return err
	}
	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 fmt.Errorf("can't parse api interval (%s)", err.Error())
		}
	}
	var sessionStore state.SessionStore
	sessionInterval := time.Duration(10 * time.Second)
	if js.config.Sessions.SessionInterval != "" {
		sessionInterval, err = time.ParseDuration(js.config.Sessions.SessionInterval)
		if err != nil {
			return fmt.Errorf("can't parse session interval (%s)", err.Error())
		}
		switch js.config.Sessions.Type {
		case "filestore":
			sessionStore = state.NewFilestore(js.config.API.Pid, js.config.Sessions.URI)
		default:
			return fmt.Errorf("provided session_store (%s) is not supported", js.config.Sessions.Type)
		}
	}
	for _, node := range js.nodes {
		n := node.CreateTransporterNode()
		pipeline, err := transporter.NewPipeline(n, js.emitter(), interval, sessionStore, sessionInterval)
		if err != nil {
			return err
		}
		js.pipelines = append(js.pipelines, pipeline) 
	}
	return nil
}
func ( js * JavascriptBuilder ) Build ( ) error { _ , err := js . vm . Run ( js . script ) if js . err != nil { return js . err } if err != nil { return err } 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 fmt . Errorf ( " " , err . Error ( ) ) } } var sessionStore state . SessionStore sessionInterval := time . Duration ( 10 * time . Second ) if js . config . Sessions . SessionInterval != " " { sessionInterval , err = time . ParseDuration ( js . config . Sessions . SessionInterval ) if err != nil { return fmt . Errorf ( " " , err . Error ( ) ) } switch js . config . Sessions . Type { case " " : sessionStore = state . NewFilestore ( js . config . API . Pid , js . config . Sessions . URI ) default : return fmt . Errorf ( " " , js . config . Sessions . Type ) } } for _ , node := range js . nodes { n := node . CreateTransporterNode ( ) pipeline , err := transporter . NewPipeline ( n , js . emitter ( ) , interval , sessionStore , sessionInterval ) if err != nil { return err } js . pipelines = append ( js . pipelines , pipeline ) } return nil }
Build runs the javascript script.
Build runs the javascript script .
// get the interval from the config, or else default to 60 seconds // build each pipeline // remember this pipeline