// The simplest usage of background bulk indexing with error channel func ExampleBulkIndexer_errorsmarter() { indexer := core.NewBulkIndexerErrors(10, 60) done := make(chan bool) indexer.Run(done) errorCt := 0 // use sync.atomic or something if you need timer := time.NewTicker(time.Minute * 3) go func() { for { select { case _ = <-timer.C: if errorCt < 2 { errorCt = 0 } case _ = <-done: return } } }() go func() { for errBuf := range indexer.ErrorChannel { errorCt++ fmt.Println(errBuf.Err) // log to disk? db? ???? Panic } }() for i := 0; i < 20; i++ { indexer.Index("twitter", "user", strconv.Itoa(i), "", nil, `{"name":"bob"}`) } done <- true // send shutdown signal }
// The simplest usage of background bulk indexing func ExampleBulkIndexer_simple() { indexer := core.NewBulkIndexerErrors(10, 60) done := make(chan bool) indexer.Run(done) indexer.Index("twitter", "user", "1", "", nil, `{"name":"bob"}`) <-done // wait forever }
// The simplest usage of background bulk indexing with error channel func ExampleBulkIndexer_errorchannel() { indexer := core.NewBulkIndexerErrors(10, 60) done := make(chan bool) indexer.Run(done) go func() { for errBuf := range indexer.ErrorChannel { // just blissfully print errors forever fmt.Println(errBuf.Err) } }() for i := 0; i < 20; i++ { indexer.Index("twitter", "user", strconv.Itoa(i), "", nil, `{"name":"bob"}`) } done <- true }