Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update executors to set offsets on consistency manager
Motivation: executors make the update or create requests and get back an offset which is saved in the consistency manager
  • Loading branch information
Rodrigo Gomez Palacio committed Oct 23, 2024
commit d09d4648e3442d34f84af31ecf6f2463bc042efa
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier)
}

OneSignalCoreImpl.sharedClient().execute(request) { _ in
OneSignalCoreImpl.sharedClient().execute(request) { response in
// On success, remove request from cache, and we do need to hydrate
// TODO: We need to hydrate after all ? What why ?
self.dispatchQueue.async {
Expand All @@ -255,6 +255,21 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}
if let onesignalId = request.identityModel.onesignalId {
if let rywToken = response?["ryw_token"] as? String
{
let rywDelay = response?["ryw_delay"] as? NSNumber

OSConsistencyManager.shared.setRywTokenAndDelay(
id: onesignalId,
key: OSIamFetchOffsetKey.userUpdate,
value: OSReadYourWriteData(rywToken: rywToken, rywDelay: rywDelay)
)
} else {
// handle a potential regression where ryw_token is no longer returned by API
OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID)
}
}
} onFailure: { error in
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSPropertyOperationExecutor update properties request failed with error: \(error.debugDescription)")
self.dispatchQueue.async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,35 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
}

OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor: executeCreateSubscriptionRequest making request: \(request)")
OneSignalCoreImpl.sharedClient().execute(request) { result in
OneSignalCoreImpl.sharedClient().execute(request) { response in
// On success, remove request from cache (even if not hydrating model), and hydrate model
self.dispatchQueue.async {
self.addRequestQueue.removeAll(where: { $0 == request})
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue)

guard let response = result?["subscription"] as? [String: Any] else {
guard let response = response?["subscription"] as? [String: Any] else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "Unabled to parse response to create subscription request")
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
return
}

if let onesignalId = request.identityModel.onesignalId {
if let rywToken = response["ryw_token"] as? String
{
let rywDelay = response["ryw_delay"] as? NSNumber
OSConsistencyManager.shared.setRywTokenAndDelay(
id: onesignalId,
key: OSIamFetchOffsetKey.subscriptionUpdate,
value: OSReadYourWriteData(rywToken: rywToken, rywDelay: rywDelay)
)
} else {
// handle a potential regression where ryw_token is no longer returned by API
OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID)
}
}

request.subscriptionModel.hydrate(response)
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
Expand Down Expand Up @@ -393,7 +409,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier)
}

OneSignalCoreImpl.sharedClient().execute(request) { _ in
OneSignalCoreImpl.sharedClient().execute(request) { response in
// On success, remove request from cache. No model hydration occurs.
// For example, if app restarts and we read in operations between sending this off and getting the response
self.dispatchQueue.async {
Expand All @@ -403,6 +419,21 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}

if let onesignalId = OneSignalUserManagerImpl.sharedInstance.onesignalId {
if let rywToken = response?["ryw_token"] as? String
{
let rywDelay = response?["ryw_delay"] as? NSNumber
OSConsistencyManager.shared.setRywTokenAndDelay(
id: onesignalId,
key: OSIamFetchOffsetKey.subscriptionUpdate,
value: OSReadYourWriteData(rywToken: rywToken, rywDelay: rywDelay)
)
} else {
// handle a potential regression where ryw_token is no longer returned by API
OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID)
}
}
} onFailure: { error in
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor update subscription request failed with error: \(error.debugDescription)")
self.dispatchQueue.async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ extension OSUserExecutor {
} else {
self.executePendingRequests()
}

if let onesignalId = request.identityModel.onesignalId {
if let rywToken = response["ryw_token"] as? String
{
let rywDelay = response["ryw_delay"] as? NSNumber
OSConsistencyManager.shared.setRywTokenAndDelay(
id: onesignalId,
key: OSIamFetchOffsetKey.userCreate,
value: OSReadYourWriteData(rywToken: rywToken, rywDelay: rywDelay)
)
} else {
// handle a potential regression where ryw_token is no longer returned by API
OSConsistencyManager.shared.resolveConditionsWithID(id: OSIamFetchReadyCondition.CONDITIONID)
}
}
}
OSOperationRepo.sharedInstance.paused = false
} onFailure: { error in
Expand Down