Skip to content

Commit c23f889

Browse files
committed
chore: go
1 parent 1668616 commit c23f889

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

templates/go/ingestion_helpers.mustache

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,33 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
5858
responses = append(responses, *resp)
5959
records = make([]map[string]any, 0, len(objects)%conf.batchSize)
6060
}
61-
}
6261

63-
if conf.waitForTasks {
64-
for _, resp := range responses {
65-
_, err := CreateIterable( //nolint:wrapcheck
66-
func(*Event, error) (*Event, error) {
67-
if resp.EventID == nil {
68-
return nil, reportError("received unexpected response from the push endpoint, eventID must not be undefined")
69-
}
70-
71-
return c.GetEvent(c.NewApiGetEventRequest(resp.RunID, *resp.EventID))
72-
},
73-
func(response *Event, err error) (bool, error) {
74-
var apiErr *APIError
75-
if errors.As(err, &apiErr) {
76-
return apiErr.Status != 404, nil
77-
}
78-
79-
return true, err
80-
},
81-
WithTimeout(func(count int) time.Duration { return time.Duration(min(500*count, 5000)) * time.Millisecond }), WithMaxRetries(50),
82-
)
83-
if err != nil {
84-
return nil, err
85-
}
86-
}
62+
63+
if conf.waitForTasks && (len(responses) % 50 == 0 || i == len(objects)-1) {
64+
for _, resp := range responses[:50] {
65+
_, err := CreateIterable( //nolint:wrapcheck
66+
func(*Event, error) (*Event, error) {
67+
if resp.EventID == nil {
68+
return nil, reportError("received unexpected response from the push endpoint, eventID must not be undefined")
69+
}
70+
71+
return c.GetEvent(c.NewApiGetEventRequest(resp.RunID, *resp.EventID))
72+
},
73+
func(response *Event, err error) (bool, error) {
74+
var apiErr *APIError
75+
if errors.As(err, &apiErr) {
76+
return apiErr.Status != 404, nil
77+
}
78+
79+
return true, err
80+
},
81+
WithTimeout(func(count int) time.Duration { return time.Duration(min(500*count, 5000)) * time.Millisecond }), WithMaxRetries(50),
82+
)
83+
if err != nil {
84+
return nil, err
85+
}
86+
}
87+
}
8788
}
8889

8990
return responses, nil

0 commit comments

Comments
 (0)