Merge branch 'bugfix/marketingCloudVisitorId_client_param_timeouts' into 'develop'

Address ClientParameter timeout logging issues

### Summary
Update timeout signature to use standard TimeInterval for split second handling.

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core/-/merge_requests/289
This commit is contained in:
Hedden, Kyle Matthew 2023-10-23 18:28:00 +00:00
commit 77ab27d79d
3 changed files with 15 additions and 13 deletions

View File

@ -104,13 +104,17 @@
timingOutIn: timeout) { (receivedParameter) in
// Queue the results for merge.
parametersWorkQueue.async {
if (returnedList[index] != nil) {
MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!)
} else {
MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId))
returnedList[index] = receivedParameter
group.leave() // Leaving is only done after setup (barriered).
guard !complete else {
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Client \(parameterType) responded after task completion.")
return
}
guard returnedList[index] == nil else {
MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!)
return
}
MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId))
returnedList[index] = receivedParameter
group.leave() // Leaving is only done after setup (barriered).
}
}
}

View File

@ -15,7 +15,7 @@ public protocol ClientParameterProtocol: ModelHandlerProtocol {
var clientParameterModel: ClientParameterModelProtocol { get set }
func fetchClientParameters(requestParameters: [String: Any], timingOutIn timeout: Double, completionHandler:@escaping ([String: AnyHashable]?) -> ())
func fetchClientParameters(requestParameters: [String: Any], timingOutIn timeout: TimeInterval, completionHandler:@escaping ([String: AnyHashable]?) -> ())
/// Default parameter for timeout scenarios. It will use the protocol extension method bydefault. Can override to send custom values.
func valueOnTimeout() -> [String: AnyHashable]
@ -28,10 +28,8 @@ public extension ClientParameterProtocol {
}
/// The handler should call this method to pass the parameter back to the caller.
func returnParameters(_ isFlatMap: Bool, _ parameter: [String: AnyHashable]?, completionHandler: @escaping ([String: AnyHashable]?) -> ()) {
guard let parameter = parameter else {
return completionHandler(nil)
}
/// If using isFlatMap, you must provide at least 1 element in parameters or it will result in triggering a timeout.
func returnParameters(_ isFlatMap: Bool, _ parameter: [String: AnyHashable], completionHandler: @escaping ([String: AnyHashable]?) -> ()) {
if isFlatMap {
completionHandler(parameter)
} else {

View File

@ -27,7 +27,7 @@ public extension MVMCoreActionUtility {
- Parameter timemout: the time the operation has to finish before throwing a timeout error.
- Parameter operation: the operation to perform.
*/
static func perform<T>(with timeout: Int = 1, operation: @escaping @Sendable () async throws -> T) async throws -> T {
static func perform<T>(withTimeout timeout: TimeInterval, operation: @escaping @Sendable () async throws -> T) async throws -> T {
return try await withCheckedThrowingContinuation { continuation in
Task {
await withThrowingTaskGroup(of: T.self) { group in
@ -40,7 +40,7 @@ public extension MVMCoreActionUtility {
// Task for time out.
group.addTask {
try Task.checkCancellation()
try await Task.sleep(nanoseconds: UInt64(timeout) * NSEC_PER_SEC)
try await Task.sleep(nanoseconds: UInt64(timeout * TimeInterval(NSEC_PER_SEC)))
throw MVMCoreActionUtilityError.timeOut
}