Skip to content

Commit

Permalink
Revert interrupt logic (#2699)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1207162593153246/f
Tech Design URL:
CC:

**Description**:
Same as #2698 but for
the internal release

**Steps to test this PR**:
1. Test the regular DBP flow
2. Specifically test editing info whilst scans are still running
3. Test opening and closing the tab repeatedly.

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
THISISDINOSAUR authored Apr 24, 2024
1 parent 73c0b1f commit a2ca57f
Showing 1 changed file with 8 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ protocol OperationRunnerProvider {
func getOperationRunner() -> WebOperationRunner
}

private enum DataBrokerProtectionProcessorFunction {
case runAllScanOperations(pendingCompletion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)?)
case runAllOptOutOperations(pendingCompletion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)?)
case runQueuedOperations(pendingCompletion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)?)
case runAllOperations(pendingCompletion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)?)
}

final class DataBrokerProtectionProcessor {
private let database: DataBrokerProtectionRepository
private let config: SchedulerConfig
Expand All @@ -42,8 +35,6 @@ final class DataBrokerProtectionProcessor {
private let engagementPixels: DataBrokerProtectionEngagementPixels
private let eventPixels: DataBrokerProtectionEventPixels

private var currentlyRunningOperationsForFunction: DataBrokerProtectionProcessorFunction?

init(database: DataBrokerProtectionRepository,
config: SchedulerConfig,
operationRunnerProvider: OperationRunnerProvider,
Expand All @@ -66,15 +57,13 @@ final class DataBrokerProtectionProcessor {
// MARK: - Public functions
func runAllScanOperations(showWebView: Bool = false,
completion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)? = nil) {
interruptCurrentlyRunningFunction()
currentlyRunningOperationsForFunction = .runAllScanOperations(pendingCompletion: completion)
operationQueue.cancelAllOperations()
runOperations(operationType: .scan,
priorityDate: nil,
showWebView: showWebView) { [weak self] errors in
showWebView: showWebView) { errors in
os_log("Scans done", log: .dataBrokerProtection)
self?.currentlyRunningOperationsForFunction = nil
completion?(errors)
self?.calculateMisMatches()
self.calculateMisMatches()
}
}

Expand All @@ -85,45 +74,37 @@ final class DataBrokerProtectionProcessor {

func runAllOptOutOperations(showWebView: Bool = false,
completion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)? = nil) {
interruptCurrentlyRunningFunction()
currentlyRunningOperationsForFunction = .runAllOptOutOperations(pendingCompletion: completion)
operationQueue.cancelAllOperations()
runOperations(operationType: .optOut,
priorityDate: nil,
showWebView: showWebView) { [weak self] errors in
showWebView: showWebView) { errors in
os_log("Optouts done", log: .dataBrokerProtection)
self?.currentlyRunningOperationsForFunction = nil
completion?(errors)
}
}

func runQueuedOperations(showWebView: Bool = false,
completion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)? = nil ) {
interruptCurrentlyRunningFunction()
currentlyRunningOperationsForFunction = .runQueuedOperations(pendingCompletion: completion)
runOperations(operationType: .all,
priorityDate: Date(),
showWebView: showWebView) { [weak self] errors in
showWebView: showWebView) { errors in
os_log("Queued operations done", log: .dataBrokerProtection)
self?.currentlyRunningOperationsForFunction = nil
completion?(errors)
}
}

func runAllOperations(showWebView: Bool = false,
completion: ((DataBrokerProtectionSchedulerErrorCollection?) -> Void)? = nil ) {
interruptCurrentlyRunningFunction()
currentlyRunningOperationsForFunction = .runAllOperations(pendingCompletion: completion)
runOperations(operationType: .all,
priorityDate: nil,
showWebView: showWebView) { [weak self] errors in
showWebView: showWebView) { errors in
os_log("Queued operations done", log: .dataBrokerProtection)
self?.currentlyRunningOperationsForFunction = nil
completion?(errors)
}
}

func stopAllOperations() {
interruptCurrentlyRunningFunction()
operationQueue.cancelAllOperations()
}

// MARK: - Private functions
Expand Down Expand Up @@ -202,25 +183,6 @@ final class DataBrokerProtectionProcessor {
return collections
}

private func interruptCurrentlyRunningFunction() {
operationQueue.cancelAllOperations()

switch currentlyRunningOperationsForFunction {
case .runAllScanOperations(let pendingCompletion),
.runAllOptOutOperations(let pendingCompletion),
.runQueuedOperations(let pendingCompletion),
.runAllOperations(let pendingCompletion):

if let pendingCompletion = pendingCompletion {
// There's a current limitation that if interrupted, we won't propagate the scan errors
pendingCompletion(DataBrokerProtectionSchedulerErrorCollection(oneTimeError: DataBrokerProtectionSchedulerError.operationsInterrupted))
}
case nil:
break
}
currentlyRunningOperationsForFunction = nil
}

deinit {
os_log("Deinit DataBrokerProtectionProcessor", log: .dataBrokerProtection)
}
Expand Down

0 comments on commit a2ca57f

Please sign in to comment.