Esempio n. 1
0
func subscriberAction(c *cli.Context) {
	initLogging(c)
	fmt.Println(c.Args())
	errc := make(chan error)
	persister, err := dagger.NewPersister(persisterConfFromFlags(c))
	if err != nil {
		log.Fatalf("error opening database")
	}
	defer persister.Close()

	prnter := &printer{dataonly: c.Bool("dataonly")}

	coordinator := dagger.NewConsulCoordinator(consulConfFromFlags(c))
	receiver := dagger.NewReceiver(coordinator, receiverConfFromFlags(c))
	go receiver.Listen(errc)

	advertiseAddr := getAdvertiseAddr(c, receiver)
	err = coordinator.Start(advertiseAddr, errc)
	defer coordinator.Stop()
	if err != nil {
		log.Fatalf("Error starting coordinator %s", err)
	}

	topicGlob := dagger.StreamID(c.Args().First())
	lwmTracker := dagger.NewLWMTracker()
	linearizer := dagger.NewLinearizer("test", persister, lwmTracker)
	linearizer.SetProcessor(prnter)
	go linearizer.Run(errc)
	from, err := strconv.ParseInt(c.String("from"), 10, 64)
	if err != nil {
		panic(err)
	}

	if !c.IsSet("groupby") {
		receiver.SubscribeTo(topicGlob, dagger.Timestamp(from), linearizer)
		log.Printf("Subscribed to %s", topicGlob)
	} else {
		matchers := strings.Split(c.String("groupby"), ",")
		varargs := make([]interface{}, len(matchers))
		for i := range matchers {
			matchers[i] = strings.TrimSpace(matchers[i])
			varargs[i] = matchers[i]
		}
		testString := fmt.Sprintf(string(topicGlob), varargs...)
		if strings.Contains(testString, "%!") {
			log.Printf("Group by parameter has too few or too many values")
			return
		}
		// go match(topicGlob, matchers, errc)
	}

	handleSignals(errc)
}
Esempio n. 2
0
func workerAction(c *cli.Context) {
	initLogging(c)
	appmetrics := c.String("appmetrics")
	if len(appmetrics) > 0 {
		// set up monitoring
		go influxdb.InfluxDB(
			metrics.DefaultRegistry, // metrics registry
			time.Second*1,           // interval
			appmetrics,              // the InfluxDB url
			"dagger",                // your InfluxDB database
			"root",                  // your InfluxDB user
			"root",                  // your InfluxDB password
		)
	}
	errc := make(chan error)

	persister, err := dagger.NewPersister(persisterConfFromFlags(c))
	if err != nil {
		log.Fatalf("Error opening database")
	}
	defer persister.Close()

	coordinator := dagger.NewConsulCoordinator(consulConfFromFlags(c))
	receiver := dagger.NewReceiver(coordinator, receiverConfFromFlags(c))

	taskStarter := dagger.NewTaskStarter(coordinator, persister, dispatcherConfFromFlags(c))
	taskManager := dagger.NewTaskManager(coordinator, receiver, taskStarter)

	advertiseAddr := getAdvertiseAddr(c, receiver)
	err = coordinator.Start(advertiseAddr, errc)
	defer coordinator.Stop()
	if err != nil {
		log.Fatalf("Error starting coordinator %s", err)
	}

	go receiver.Listen(errc)
	go taskManager.ManageTasks()

	dispatcher := dagger.NewDispatcher(coordinator)
	httpapi := dagger.NewHttpAPI(coordinator, receiver, dispatcher)
	go httpapi.Serve()

	handleSignals(errc)
}