46 lines
713 B
Go
46 lines
713 B
Go
package elasticstream
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
// "github.com/elastic/go-elasticsearch/v8"
|
|
)
|
|
|
|
type Worker struct {
|
|
client *Client
|
|
index string
|
|
offset int
|
|
size int
|
|
}
|
|
|
|
func NewWorker(client *Client, index string, offset, size int) {
|
|
w := &Worker{
|
|
client: client,
|
|
index: index,
|
|
offset: offset,
|
|
size: size,
|
|
}
|
|
|
|
go w.start()
|
|
}
|
|
|
|
func (w *Worker) start() {
|
|
|
|
for {
|
|
log.Printf("worker index=%s offset=%d size=%d\n", w.index, w.offset, w.size)
|
|
|
|
dataArray, err := search(w.client.es, w.index, &w.offset, &w.size)
|
|
if err != nil {
|
|
log.Println("search() err:", err)
|
|
time.Sleep(1 * time.Second)
|
|
continue
|
|
}
|
|
|
|
for _, data := range dataArray {
|
|
w.client.ch <- data
|
|
w.offset++
|
|
}
|
|
}
|
|
|
|
}
|