-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Don't retry tasks when running in foreground #6900
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
Conversation
|
To keep track of steps to reproduce and the expected behavior: Steps to reproduce:
Expected behavior @seadowg Please verify if the step to reproduce and expected behavior are ok. |
|
If the steps to reproduce and the expected behavior described above are ok, then the notifications isn't shown in this case on Android 10 and 16. |
That looks right to me. That's consistent with Collect v2025.2.3 right?
In this PR? I'll have a look. |
Yes in the PR |
|
@dbemke yeah looks like there's a second bug, to fix to get this working. I'll remove "needs testing" while I deal with that. |
|
@dbemke ok that should all be working now! |
First test - it seems to be working well so I'll add "needs testing" label |
| try { | ||
| val completed = | ||
| taskSpec.getTask(applicationContext, stringInputData, isLastUniqueExecution(taskSpec)) { isStopped }.get() | ||
| taskSpec.getTask(applicationContext, stringInputData, foreground || isLastUniqueExecution(taskSpec)) { isStopped }.get() |
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 should always count a foreground task as the last execution so that jobs like SyncFormTaskSpec switch to the behaviour they would use in that mode (like notifying about errors).
| return if (completed) { | ||
| Result.success() | ||
| } else if (maxRetries == null || runAttemptCount < maxRetries) { | ||
| } else if (!foreground && (maxRetries == null || runAttemptCount < maxRetries)) { |
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 don't want to retry when running in the foreground: it doesn't fit with the idea of having more immediate results/feedback, and it also could cause errors (foreground services should not be started in the background).
| private const val SYNC_NOTIFICATION_CHANNEL_NAME = "Form updates" | ||
|
|
||
| private const val SYNC_NOTIFICATION_ID = 1 | ||
| private const val SYNC_NOTIFICATION_ID = 3 |
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.
It seems like we've made an assumption in the code base that notifications are identified by their ID and their channel. In fact, they are only identified by ID, so this should be unique.
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.
Could you elaborate on this? Why 3? What was the issue here?
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.
If this is 1, it has the same ID as the error notification (FORM_SYNC_NOTIFICATION_ID) so the error gets cleared when the foreground service hides its notification. We're going to want to work out a centralized source for these IDs, but I wanted to leave that for once we've got tests (#6902).
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're going to want to work out a centralized source for these IDs
Yes, this would be important to make it clear. Will that be added to #6902 or a separate 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'll add that to #6902. Right now it's just failing tests (one of which drives out this change). That PR will be the master version of these changes.
|
Tested with success Verified on device with android 16 Verified cases:
|
|
Tested with success Verified on device with android 10 |
Don't retry tasks when running in foreground
This should fix a problem (pointed out by @lognaturel on Slack) where error notifications are not being shown after manually refreshing a project from the "Start new form" screen.
Why is this the best possible solution? Were any other approaches considered?
Comments inline.
Also: the 3 changes here aren't tested - initially this was just because I wasn't confident about how to fix so was relying on manual testing between myself and QA to get things right. When then trying to write tests, I discovered we're going to need to rework things - our current
TaskSpecWorkerTestcrashes ifsetForegroundAsyncis called and ourTestScheduleris not set up to test real foreground service behaviour. I'll follow up with a PR that adds coverage for all three changes here.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
The only thing affected here is that notifications should be shown for errors that happen when manually refreshing.
Before submitting this PR, please make sure you have:
./gradlew connectedAndroidTest(or./gradlew testLab) and confirmed all checks still passDateFormatsTest