Ejemplo n.º 1
0
// StartAll creates and starts a new listener for each application
// registered in the store.
func StartAll(s source.ConfigSource, queue Queue) error {
	appNames, err := s.ListAppNames()
	if err != nil {
		return err
	}
	if len(appNames) == 0 {
		log.Print("No applications found. Exiting.")
		return nil
	}

	errc := make(chan int, len(appNames))
	qc := make(chan *Tweet, len(appNames)*100)
	queue.Start(qc)

	allListeners := make([]Listener, 0, len(appNames))
	for _, name := range appNames {
		storedApp, getErr := s.GetApp(name)
		if getErr != nil {
			log.Printf("ERROR fetching app %q: %v", name, getErr)
			continue
		}

		userIDs, userErr := s.ListTwitterIDs(name)
		if userErr != nil {
			return userErr
		}

		listener := NewListener(storedApp, userIDs, qc, errc)
		allListeners = append(allListeners, listener)
		go listener.Start()
	}
	aw := NewAppWatcher(APP_TOPIC, allListeners, s)
	return aw.Watch(qc, errc)
}
Ejemplo n.º 2
0
// StartOne creates and starts one listener for the specified application.
func StartOne(appName string, s source.ConfigSource, queue Queue) error {
	app, err := s.GetApp(appName)
	if err != nil {
		return err
	}
	userIDs, userErr := s.ListTwitterIDs(appName)
	if userErr != nil {
		return userErr
	}
	if len(userIDs) == 0 {
		log.Printf("No users found for app %q. Exiting.", appName)
		return nil
	}

	qc := make(chan *Tweet, 100)
	queue.Start(qc)

	errc := make(chan int, 1)
	listener := NewListener(app, userIDs, qc, errc)
	listener.Start()

	aw := NewAppWatcher(APP_TOPIC, []Listener{listener}, s)
	return aw.Watch(qc, errc)
}