コード例 #1
0
// 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
	}

	// 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 fmt.Errorf("can't parse api interval (%s)", err.Error())
		}
	}

	// build each pipeline
	for _, node := range js.nodes {
		n := node.CreateTransporterNode()
		pipeline, err := transporter.NewPipeline(n, js.emitter(), interval)
		if err != nil {
			return err
		}
		js.pipelines = append(js.pipelines, pipeline) // remember this pipeline
	}

	return nil
}
コード例 #2
0
// 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
	}

	// 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 fmt.Errorf("can't parse api interval (%s)", err.Error())
		}
	}

	var sessionStore state.SessionStore
	sessionInterval := time.Duration(10 * time.Second)
	fmt.Printf("js sessions config -> %v\n", js.config.Sessions)
	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)
		}
	}

	// build each pipeline
	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) // remember this pipeline
	}

	return nil
}