fix: resolve issue #622 - periodic tasks running at incorrect frequencies#628
Merged
fix: resolve issue #622 - periodic tasks running at incorrect frequencies#628
Conversation
…cies BREAKING CHANGE: Separate ExistingWorkPolicy and ExistingPeriodicWorkPolicy enums - registerPeriodicTask now requires ExistingPeriodicWorkPolicy instead of ExistingWorkPolicy - This mirrors Android's native WorkManager API design for better type safety Changes: - Change default periodic work policy from KEEP to UPDATE - UPDATE policy ensures new task configurations replace existing ones - Add comprehensive documentation with upstream Android links - Update example app with periodic task demo using UPDATE policy - Update all packages to use the new separated policy types Fixes #622 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
To view this pull requests documentation preview, visit the following URL: docs.page/fluttercommunity/flutter_workmanager~628 Documentation is deployed and generated using docs.page. |
- Add build_runner dependency to workmanager package - Fix .mocks.dart generation with proper ExistingPeriodicWorkPolicy types - Update generated mocks to reflect new API separation - Clean up documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…mand - Add new GitHub Actions workflow to ensure generated files are up-to-date - Create parent 'generate' command that runs both pigeon and dart generation - Update generate:pigeon to use --depends-on filter for consistency - Workflow fails PR builds if generated files are not committed This ensures the repository always contains current generated files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update example and platform interface pubspec files - Ensure version consistency across packages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The build.yaml file is not needed as mockito automatically discovers test files with @GenerateMocks annotations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes issue #622 where periodic tasks on Android were running at incorrect frequencies when re-registered with different intervals. The solution introduces a separate ExistingPeriodicWorkPolicy enum and changes the default policy from KEEP to UPDATE to ensure new task configurations replace existing ones.
- Separate
ExistingWorkPolicyandExistingPeriodicWorkPolicyenums for better type safety - Change default periodic work policy from
KEEPtoUPDATEto fix frequency persistence issue - Update all platform implementations to use the new enum type consistently
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| workmanager_platform_interface/pigeons/workmanager_api.dart | Added new ExistingPeriodicWorkPolicy enum with comprehensive documentation |
| workmanager_platform_interface/lib/src/workmanager_platform_interface.dart | Updated method signature to use ExistingPeriodicWorkPolicy |
| workmanager_android/android/src/main/kotlin/dev/fluttercommunity/workmanager/WorkManagerUtils.kt | Changed default policy to UPDATE and updated mapping function |
| workmanager/lib/src/workmanager_impl.dart | Updated method signature to match platform interface |
| example/lib/main.dart | Added demonstration of UPDATE policy with frequency selection |
Comments suppressed due to low confidence (2)
workmanager_platform_interface/pubspec.yaml:19
- Removing flutter_test dependency from dev_dependencies may break existing development workflows or CI/CD pipelines that depend on it for testing. Consider if this removal is intentional and necessary.
dev_dependencies:
example/pubspec.yaml:21
- Removing flutter_test dependency from the example app's dev_dependencies may prevent running tests for the example. This could impact the ability to validate example functionality through automated testing.
flutter_lints: ^6.0.0
- Fix type error in workmanager_integration_test.dart - Use ExistingPeriodicWorkPolicy instead of ExistingWorkPolicy for periodic tasks - Add 'dart analyze' to pre-commit checklist to catch code errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #622 where periodic tasks on Android were running at incorrect frequencies when re-registered with different intervals.
Fixes #622
Problem
When developers register a periodic task multiple times with the same unique name but different frequencies (common during development), the original task frequency persists due to the default
ExistingPeriodicWorkPolicy.KEEPbehavior.Example scenario:
Solution
Changed default policy from
KEEPtoUPDATEfor periodic tasksUPDATEpolicy ensures new configurations replace existing onesREPLACE- doesn't cancel running workersBREAKING: Separated
ExistingWorkPolicyandExistingPeriodicWorkPolicyenumsregisterPeriodicTasknow requiresExistingPeriodicWorkPolicyChanges
UPDATEinWorkManagerUtils.ktExistingPeriodicWorkPolicyenum in Pigeon APITesting
Breaking Change
Before:
After:
This is a well-justified breaking change that improves API clarity and prevents developer confusion.
🤖 Generated with Claude Code