Skip to content

Commit

Permalink
feat: add constraint for GetCUrsor (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
crimson-gao authored Nov 29, 2024
1 parent ba312b9 commit 8e36402
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/consumer/with_log_id/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
ConsumerGroupName: "test-consumer",
ConsumerName: "test-consumer-1",
CursorPosition: consumerLibrary.END_CURSOR,
Query: "", // query must be empty string or not initialized, GetCursor only support empty query
}

worker := consumerLibrary.InitConsumerWorkerWithCheckpointTracker(option, process_with_log_id)
Expand All @@ -40,6 +41,7 @@ func process_with_log_id(shardId int, logGroupList *sls.LogGroupList, checkpoint
// start consume logs
for _, logGroup := range logGroupList.LogGroups {
// logGroupCursor is empty string if failed
// only support consumer without query
logGroupCursor := logGroup.GetCursor()
fmt.Println("log group cursor: ", logGroupCursor)

Expand Down
2 changes: 1 addition & 1 deletion log_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func (s *LogStore) PullLogsWithQuery(plr *PullLogRequest) (gl *LogGroupList, plm
if err != nil {
return nil, nil, err
}
if plm.Count > 0 && plm.readLastCursor != "" {
if plm.Count > 0 && plm.readLastCursor != "" && plr.Query == "" {
gl.addCursorIfPossible(plm.readLastCursor)
}
return
Expand Down
1 change: 1 addition & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ type ListStoreViewsResponse struct {
}

// If cursor is unknown, returns empty string
// If pullLogs with non-empty query or consumer with non-empty query, returns empty string
func (l *LogGroup) GetCursor() string {
return l.cursor
}
Expand Down

0 comments on commit 8e36402

Please sign in to comment.