feat(android): work chaining via beginUniqueWork - #718
Draft
ened wants to merge 3 commits into
Draft
Conversation
|
To preview the documentation for this pull request, visit the following URL: docs.page/fluttercommunity/flutter_workmanager~718
|
- WorkManagerUtils: keep both the one-off builder (main) and the chain builder; chain builder drops the implicit setExpedited (aligned with 0.10.2 explicit-only expedited semantics) - WorkmanagerPlugin: both getWorkInfo and beginUniqueWork imports - tests: rebuild the conflict-spliced test files from both source commits (expedited + work-info groups from main, chaining group from the original branch); apple tests get the beginUniqueWork UnsupportedError test inserted into main's file - pigeon regenerated from the merged source
- WorkManagerUtils: keep both the one-off builder (main) and the chain builder; chain builder drops the implicit setExpedited (aligned with 0.10.2 explicit-only expedited semantics) - WorkmanagerPlugin: both getWorkInfo and beginUniqueWork imports - tests: rebuild the conflict-spliced test files from both source commits; apple tests get the beginUniqueWork UnsupportedError test - pigeon regenerated from the merged source
ened
force-pushed
the
feat/work-chaining
branch
from
August 3, 2026 16:50
cb3fcf5 to
2c490f2
Compare
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
Implements audit gap #4: WorkManager sequential work chaining (
beginUniqueWork(...).then(...).enqueue()) for Android.API shape
Why this shape (and the refinements vs. the raw proposal):
WorkChainTaskis the unit of chaining. It mirrors the per-task configuration ofregisterOneOffTaskminus the unique name (inputData,initialDelay,constraints,backoffPolicy/backoffPolicyDelay,tag,outOfQuotaPolicy,foregroundServiceConfig), so each chain step is a fully-specified one-off task. This is a faithful mapping: WorkManager chains are built fromOneTimeWorkRequests.taskslist, not a fluent builder.beginUniqueWork(name, policy, first).then(...).enqueue()is exactly what the list maps to — first element starts the chain, the rest arethen()-appended. A builder would add API surface without extra expressiveness, since WorkManager's branching (beginWith/combine) is intentionally out of scope.existingWorkPolicysemantics asregisterOneOffTask(including the existingappend → APPEND_OR_REPLACEmapping, kept for consistency).tasksthrowsArgumentErroron the Dart side (andIllegalArgumentExceptionas a native backstop).Ordering & failure semantics
Result.success().Result.failure(), and WorkManager stops the chain — remaining steps never run. (Verified natively: dependents are failed/cancelled by WorkManager and theirrunAttemptCountstays 0.)falseis a retry, not a failure: consistent with one-off tasks, returningfalsemaps toResult.retry()— the chain holds and retries that step with its backoff policy before moving on. This is documented.Android-only statement
Chaining is WorkManager-specific. The API exists on every platform (so code compiles everywhere) but:
WorkmanagerApple.beginUniqueWorkthrowsUnsupportedError('Work chaining is not supported on iOS/macOS')— the same fail-loud pattern ascancelByTag/isScheduledByUniqueNameon iOS.WorkmanagerWeb.beginUniqueWorkthrowsUnsupportedError.docs/customization.mdxand the capability matrix.Compatibility
All new API — nothing existing changes. No signatures altered, no behavior changes to one-off/periodic registration. The one-off request builder was extracted into a shared internal
createOneTimeWorkRequest(identical behavior, verified by the existing test suite). New Pigeon messages are additive;work-runtime 2.11.2confirmed to havebeginUniqueWork(String, ExistingWorkPolicy, OneTimeWorkRequest),WorkContinuation.then,enqueue.Tests
UnsupportedErroron Apple/Web.WorkChainingTest, followingConstraintsMappingTestpatterns): chain enqueued with correct prerequisite order, task-name/input-data payload convention, successful chain completes in sequence, a permanently failed step stops the chain (dependents never run),ExistingWorkPolicy.REPLACEapplies to the chain, per-step backoff applied. Usesandroidx.work:work-testing's synchronous driver (test-only dependency).Docs & example
docs/customization.mdx: new "Work Chaining (Android only)" section (what it's for, ordering guarantee, failure semantics incl.false→retry, existing-work-policy note, conditional-chain guidance).docs/index.mdx: capability-matrix row (Android ✅, others ❌/UnsupportedError).Checks
melos bootstrap✅ ·dart analyzeclean ✅ ·flutter testall packages ✅ ·./gradlew :workmanager_android:test(37 tests) ✅ ·dart formatclean ✅ · ktlint clean ✅ ·flutter build apk --debug✅