81e7223560
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package clientsync
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
"log/slog"
|
|
|
|
docsyncrunner "queryorchestration/api/docSyncRunner"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
)
|
|
|
|
func (s *Service) Sync(ctx context.Context, id string) error {
|
|
hasMore := true
|
|
offset := int32(0)
|
|
dbid := id
|
|
|
|
for hasMore {
|
|
ids, err := s.cfg.GetDBQueries().ListDocumentIDsBatch(ctx, &repository.ListDocumentIDsBatchParams{
|
|
Batchsize: s.batchSize,
|
|
Pageoffset: offset,
|
|
Clientid: dbid,
|
|
})
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil
|
|
} else if err != nil {
|
|
return err
|
|
}
|
|
|
|
slog.Debug("batch processing", "id", id, "offset", offset, "length", len(ids))
|
|
|
|
for _, id := range ids {
|
|
err := s.cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: s.cfg.GetDocumentSyncURL(),
|
|
Body: docsyncrunner.Body{
|
|
DocumentID: *id.ID,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
offset += s.batchSize
|
|
if len(ids) == 0 || ids[0].Totalcount == nil || int64(offset) >= *ids[0].Totalcount {
|
|
hasMore = false
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|