feat: implement retry logic for processing tariff chunks in repository API
This commit is contained in:
@@ -216,18 +216,25 @@ func (r *apiRepository) CalculateProductTariffs(ctx context.Context, marketplace
|
|||||||
}
|
}
|
||||||
|
|
||||||
offerChunks := lo.Chunk(req.Offers, defaultChunkSize)
|
offerChunks := lo.Chunk(req.Offers, defaultChunkSize)
|
||||||
|
maxRetries := 5
|
||||||
for chunkIndex, offerChunk := range offerChunks {
|
for chunkIndex, offerChunk := range offerChunks {
|
||||||
fmt.Printf("Processing chunk %d/%d with %d offers\n", chunkIndex+1, len(offerChunks), len(offerChunk))
|
fmt.Printf("Processing chunk %d/%d with %d offers\n", chunkIndex+1, len(offerChunks), len(offerChunk))
|
||||||
|
var globalError error = nil
|
||||||
|
for range maxRetries {
|
||||||
response, err := r.processTariffChunk(ctx, client, ymParameters, offerChunk, chunkIndex)
|
response, err := r.processTariffChunk(ctx, client, ymParameters, offerChunk, chunkIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- err
|
globalError = err
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if response != nil {
|
if response != nil {
|
||||||
resultChan <- []*pb.CalculateProductTariffsResponse{response}
|
resultChan <- []*pb.CalculateProductTariffsResponse{response}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if globalError != nil {
|
||||||
|
fmt.Printf("Error processing chunk %d: %s\n", chunkIndex+1, err)
|
||||||
|
errChan <- fmt.Errorf("failed to process chunk %d: %w", chunkIndex+1, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,12 +265,16 @@ func (r *apiRepository) processTariffChunk(ctx context.Context, client *ymclient
|
|||||||
CalculateTariffsRequest(*ymRequest).
|
CalculateTariffsRequest(*ymRequest).
|
||||||
Execute()
|
Execute()
|
||||||
|
|
||||||
if httpResp != nil && httpResp.Body != nil {
|
|
||||||
_ = httpResp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if httpResp != nil && httpResp.Body != nil {
|
||||||
|
bodyData := make([]byte, 2048)
|
||||||
|
_, httpErr := httpResp.Body.Read(bodyData)
|
||||||
|
if httpErr == nil {
|
||||||
|
fmt.Printf("Error response for chunk %d: %s\n", chunkIndex+1, string(bodyData))
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil, fmt.Errorf("failed to call Yandex Market API for chunk %d: %w", chunkIndex+1, err)
|
return nil, fmt.Errorf("failed to call Yandex Market API for chunk %d: %w", chunkIndex+1, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if response == nil || response.Result == nil {
|
if response == nil || response.Result == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user