Skip to content

Commit

Permalink
feat(GiniCaptureSDK): retry logic for feedback in DocumentService
Browse files Browse the repository at this point in the history
PP-615
  • Loading branch information
mrkulik committed Nov 20, 2024
1 parent e21771e commit 9002004
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,38 @@ public final class DocumentService: DocumentServiceProtocol {
Log(message: "Cannot send feedback: no document", event: .error)
return
}
captureNetworkService.sendFeedback(document: document,
attemptFeedback(document: document,
updatedExtractions: updatedExtractions,
updatedCompoundExtractions: updatedCompoundExtractions,
retryCount: 3)
}

private func attemptFeedback(document: Document,
updatedExtractions: [Extraction],
updatedCompoundExtractions: [String: [[Extraction]]]?,
retryCount: Int) {
captureNetworkService.sendFeedback(document: document,
updatedExtractions: updatedExtractions,
updatedCompoundExtractions: updatedCompoundExtractions) { result in
switch result {
case .success:
Log(message: "Feedback sent with \(updatedExtractions.count) extractions and \(updatedCompoundExtractions?.count ?? 0) compound extractions",
event: "🚀")
case .failure(let error):
let message = "Error sending feedback for document with id: \(document.id) error: \(error)"
Log(message: message, event: .error)
let errorLog = ErrorLog(description: message, error: error)
GiniConfiguration.shared.errorLogger.handleErrorLog(error: errorLog)
if retryCount > 0 {
Log(message: "Retrying feedback due to error: \(error). Remaining retries: \(retryCount - 1)", event: .warning)
DispatchQueue.global().asyncAfter(deadline: .now() + 5) {
self.attemptFeedback(document: document,
updatedExtractions: updatedExtractions,
updatedCompoundExtractions: updatedCompoundExtractions,
retryCount: retryCount - 1)
}
} else {
let message = "Error sending feedback for document with id: \(document.id) error: \(error)"
Log(message: message, event: .error)
let errorLog = ErrorLog(description: message, error: error)
GiniConfiguration.shared.errorLogger.handleErrorLog(error: errorLog)
}
}
}
}
Expand Down

0 comments on commit 9002004

Please sign in to comment.