Fix sending OnFinish to in-flight async API calls in scheduler

This commit is contained in:
Maciej Skoczeń
2025-11-06 12:00:37 +00:00
parent 0c2aa7fee2
commit a9dcc8e2c9

View File

@@ -122,12 +122,14 @@ func (cq *callQueue) merge(oldAPICall, apiCall *queuedAPICall) error {
return err
}
if oldAPICall.CallType() != apiCall.CallType() {
if cq.inFlightEntities.Has(oldAPICall.UID()) {
// Old API call is in-flight. The new call needs to wait for the old one to finish.
return nil
}
// API call types don't match, so we overwrite the old one.
// Update the pending calls metric if the old call is not in-flight.
if !cq.inFlightEntities.Has(oldAPICall.UID()) {
metrics.AsyncAPIPendingCalls.WithLabelValues(string(oldAPICall.CallType())).Dec()
metrics.AsyncAPIPendingCalls.WithLabelValues(string(apiCall.CallType())).Inc()
}
metrics.AsyncAPIPendingCalls.WithLabelValues(string(oldAPICall.CallType())).Dec()
metrics.AsyncAPIPendingCalls.WithLabelValues(string(apiCall.CallType())).Inc()
oldAPICall.sendOnFinish(fmt.Errorf("a more relevant call was enqueued for this object: %w", fwk.ErrCallOverwritten))
return nil
}