-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Queue Manager for State & Interruption Management #2757
Implement Queue Manager for State & Interruption Management #2757
Conversation
shouldRunNextStep: { [weak self] in | ||
guard let self = self else { return false } | ||
return !self.isCancelled | ||
}) | ||
|
||
if let sleepInterval = brokerTimeInterval { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brokerTimeInterval
was optional in this type, but was always passed in as a parameter. Optionality was unnecessary.
mismatchCalculator: MismatchCalculator, | ||
brokerUpdater: DataBrokerProtectionBrokerUpdater?) | ||
|
||
func startImmediateOperationsIfPermitted(showWebView: Bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming here IMO better reflects the difference between scan types - immediate or schedule (i.e both time based).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some confusion about the language we use here in the past, so it would be good to align on it more broadly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I am happy to make broader renaming changes as part of this work (e.g there are a lot of places we reference …manualScan
and runQueuedOperations
). Proposal:
Old Naming
...manualScan
(e.gstartManualScan
,isManualScan
, etc.)runQueuedOperations
New Naming Proposal 1
...immediateOperations
(e.gstartImmediateOperations
,isImmediateOperation
, etc.)startScheduledOperations
New Naming Proposal 2
…manualOperations
(e.gstartManualOperations
,isManualOperation
, etc.)startAutomaticOperations
My preference is for Proposal 1, but I’d be happy with either (or other suggestions). The goal is to correctly capture the intent, and also align the two method names to be relative to each other.
What do you think @THISISDINOSAUR @Bunn ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about #1 but with jobs instead of operations? I think we should make "job" the chosen word for the actual thing we care about, and "operation" an implementation detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m unsure if we should use Job
here, as we recently renamed the old DataBrokerOperation
to be DataBrokerJob
(and then have ScanJob
..etc.). We also have related types like WebJobRunner
. However, the intended relationship between the top-level Operation
and lower-level jobs is a bit unclear to me. @Bunn , do you have any thoughts on Operation
and Job
naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer # 1 as it is. They are going to run the actual 'NS'Operation, so I think the naming makes sense. If it were startScheduledJobs, for example, it also makes sense to me. However, DataBrokerOperation has jobs, and what the manager does is prepare DataBrokerOperation to run the jobs. In my opinion, there's no need to call it jobs.
All that said, both would be semantically correct in my opinion, so I have no strong preference, but a slight preference for # 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool, thanks all. I’ll go with proposal 1 as it is. I’ll rename in all places in this PR, but contain the renaming to one commit.
...okerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
Outdated
Show resolved
Hide resolved
} | ||
|
||
operationQueue.addBarrierBlock { [weak self] in | ||
let errorCollection = self?.errorCollection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer capture the operations and loop over them to get errors, but rather only rely on delegation from the DataBrokerOperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly weary of getting the state management wrong there, but it's the only way to do it correctly really for the interrupting logic
…rokerProtectionQueueMode`. Add `DataBrokerDebugCommand` and associated protocol. Add initial set of tests.
665b47e
to
6c4a23b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall!
...erProtection/Sources/DataBrokerProtection/Operations/DataBrokerProtectionBrokerUpdater.swift
Outdated
Show resolved
Hide resolved
...rces/DataBrokerProtection/Operations/ParentChildRelationship/MismatchCalculatorUseCase.swift
Outdated
Show resolved
Hide resolved
...okerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
Show resolved
Hide resolved
mismatchCalculator: MismatchCalculator, | ||
brokerUpdater: DataBrokerProtectionBrokerUpdater?) | ||
|
||
func startImmediateOperationsIfPermitted(showWebView: Bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had some confusion about the language we use here in the past, so it would be good to align on it more broadly
...okerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
Outdated
Show resolved
Hide resolved
...okerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
Outdated
Show resolved
Hide resolved
} | ||
|
||
operationQueue.addBarrierBlock { [weak self] in | ||
let errorCollection = self?.errorCollection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly weary of getting the state management wrong there, but it's the only way to do it correctly really for the interrupting logic
...okerProtection/Sources/DataBrokerProtection/Scheduler/DataBrokerProtectionQueueManager.swift
Outdated
Show resolved
Hide resolved
...BrokerProtection/Tests/DataBrokerProtectionTests/DataBrokerProtectionQueueManagerTests.swift
Show resolved
Hide resolved
...kages/DataBrokerProtection/Sources/DataBrokerProtection/Operations/DataBrokerOperation.swift
Outdated
Show resolved
Hide resolved
Most feedback addressed @THISISDINOSAUR. Only remaining feedback is re: naming of Operation/Job, and I’ll wait for more input from @Bunn here. |
|
||
firePixels(operationDependencies: operationDependencies) | ||
|
||
addOperations(withType: type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operations are always added without a priority date. This means that every time the scheduler runs, it will run all operations, ignoring the preferredRunDate
for those operations.
The startScheduledOperationsIfPermitted
function should send Date()
as the priority date so the system can correctly run operations using the preferredRunDate
.
![image](https://private-user-images.githubusercontent.com/782316/330098484-48e7f840-4cc7-4364-9a0f-96a436a95cb1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMzAyODYsIm5iZiI6MTczOTEyOTk4NiwicGF0aCI6Ii83ODIzMTYvMzMwMDk4NDg0LTQ4ZTdmODQwLTRjYzctNDM2NC05YTBmLTk2YTQzNmE5NWNiMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOVQxOTM5NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zZWZhMzhiZGZhNGRkNTdiYWJhN2RjZWI1MGY1ZTIwM2UwMTVjNTdlYjgwYWZlZjE1ODZmMmI4OWQ5NmE1NDIzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.rw-KOlC6lY2G5NxrU7-EXtgs186vV6A6nifqQJKKhGk)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, great find @Bunn. I’ll push a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to meaningfully unit test for this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve added to the existing tests to ensure that the priorityDate
is passed when running scheduled operations. I think further testing could be done lower down when we check dates and decide to run or not etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interruption looks good, but there's a bug where we are ignoring the scheduler preferredRunDate and every time it runs, it runs all operations
@THISISDINOSAUR & @Bunn - I’ve implemented all feedback. See the latest commits for relevant changes. |
XCTAssertNil(result) | ||
} | ||
|
||
func testWhenModeIsScheduled_thenPriorityDateIsNotNil() throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome :)
Task/Issue URL: https://app.asana.com/0/1199230911884351/1207338264132623/f Tech Design URL: https://app.asana.com/0/481882893211075/1207174884557414/f CC: **Description**: This PR has the effect of mergeing four different PRs into main: #2777 #2758 #2757 #2743 This covers significant changes to the XPC interface and how the main app uses it, the background manager, the scheduler, and the processor. See individual PRs for details. There's no code changes here that haven't been reviewed separately as part of those PRs, so it's up to you how you want to review it code wise. The more important step at this stage is manual testing. **Steps to test this PR**: 1. Because this is a fairly significant set of changes, we need to be as thorough as we can in testing DBP generally works and really try to break it. Because of this, I'm keen that anyone testing things of their own ways to break it before trying the steps below. 2. Edit/add profile data, and before scans finish, edit it again. Scans should start afresh, and you should see an interrupted pixel fire. Check that you don't get a scans completed notification 3. Edit/add profile data, and before scans finish, close the app, and reopen it. The same set of manual scans should still continue, and a blocked pixel should fire. 4. With profile data already existing but initial scans having finished, close the app and reopen it. Scheduled scans should run. 5. With profile data already existing, and with the app closed, launch the background agent, scheduled scans should run 6. Edit/add profile data, put the laptop to sleep/lock it/restart it, check that scans continue as expected. 7. Check that the background agent activity lines up with the UI, I.e. the progress bar and when we sent the scans completed notification is accurate <!-- 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) --------- Co-authored-by: Pete Smith <[email protected]>
Task/Issue URL: https://app.asana.com/0/0/1207231867963533/f
Tech Design URL: https://app.asana.com/0/0/1207199754528649/f
Description:
This PR introduces
DataBrokerProtectionQueueManager
to manage state and logic relating to theOperationQueue
which runs DBP operations. The mains changes includes are:DataBrokerProtectionQueueManager
and related tests, mocksDataBrokerProtectionQueueMode
and related tests, mocksDataBrokerProtectionProcessor
DataBrokerOperation
to the queue manager. Uses this for all access to operations errors (the old processor had a delegate also, but also explicitly looped over errors stored in operations)DataBrokerOperationDependencies
, adding the configrunAllOperations
and allow subsequent implementations of itNote 1: As this PR replaces the
DataBrokerProtectionProcessor
type completely, it’s best to review the newDataBrokerProtectionQueueManager
type while having the existing processor open in another window. This will allow for comparison of implementation, and help highlight what has explicitly changedNote 2: To ensure the logic is correct re: queue state management, I believe it’s best to focus reviewing efforts on
DataBrokerProtectionQueueManager
andDataBrokerProtectionQueueMode
, and their related tests. The tests describe what I understand to be the expected behavior.Steps to test this PR:
Test 1
Test 2
Test 3
106-107
ofDataBrokerProtectionScheduler
to cause the scheduler to start soon after a manual scan, i.eDefaultDataBrokerProtectionQueueManager
line103
)<!—
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
Software Engineering Expectations
Technical Design Template
Pull Request Documentation