@@ -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