// Run runs the specified continuous query, or all CQs if none is specified. func (s *Service) Run(database, name string, t time.Time) error { var dbs []meta.DatabaseInfo if database != "" { // Find the requested database. db, err := s.MetaClient.Database(database) if err != nil { return err } else if db == nil { return tsdb.ErrDatabaseNotFound(database) } dbs = append(dbs, *db) } else { // Get all databases. var err error dbs, err = s.MetaClient.Databases() if err != nil { return err } } // Loop through databases. s.mu.Lock() defer s.mu.Unlock() for _, db := range dbs { // Loop through CQs in each DB executing the ones that match name. for _, cq := range db.ContinuousQueries { if name == "" || cq.Name == name { // Remove the last run time for the CQ if _, ok := s.lastRuns[cq.Name]; ok { delete(s.lastRuns, cq.Name) } } } } // Signal the background routine to run CQs. s.RunCh <- &RunRequest{Now: t} return nil }
// Run runs the specified continuous query, or all CQs if none is specified. func (s *Service) Run(database, name string) error { var dbs []meta.DatabaseInfo if database != "" { // Find the requested database. db, err := s.MetaStore.Database(database) if err != nil { return err } else if db == nil { return tsdb.ErrDatabaseNotFound(database) } dbs = append(dbs, *db) } else { // Get all databases. var err error dbs, err = s.MetaStore.Databases() if err != nil { return err } } // Loop through databases. for _, db := range dbs { // Loop through CQs in each DB executing the ones that match name. for _, cq := range db.ContinuousQueries { if name == "" || cq.Name == name { // Reset the last run time for the CQ. s.lastRuns[cq.Name] = time.Time{} } } } // Signal the background routine to run CQs. s.RunCh <- struct{}{} return nil }