Skip to content

🐞Bug - initDelay in registerPeriodicTask is now useless #594

Open
@BigYajuu

Description

@BigYajuu
  • I have read the README
    I have done the setup for Android
    I have done the setup for iOS
    I have ran the sample app and it does not work there
Technology Version
Workmanager version main branch
Xcode version -
Swift version -
iOS deployment target -

Describe the error
Note: I'm using this plugin's main branch.

When I invoke 'registerPeriodicTask' with initDelay and frequency durations stated I expect the callback to get called after initDelay duration from now, then gets called again in frequency.

Problem: initDelay was completely ignored and the first periodic task runs after stated frequency duration. It's weird because before I swapped to this branch, it works just fine.

Bumping back to the official pubspec version won't solve my issue because there's #588 .

Sample Code

  static Future testRunPeriodic() async {
    await Workmanager().registerPeriodicTask(
      "peridicChicken",
      "periodicChickenName",
      initialDelay: const Duration(minutes: 2),
      frequency: const Duration(minutes: 15),
      inputData: {
        "isTest": true,
      },
    );
  }

We can see that initDelay is set to 2 minutes, but the callback gets invoked in 15 minutes instead.

Activity

Manuito83

Manuito83 commented on Apr 2, 2025

@Manuito83

@BigYajuu I saw the same and I've been doing some tests. I think this is not this package's fault, but instead a consequence of upgrading the native WorkManager version as per this line here that bumps it v2.9.0:

def work_version = "2.9.0"

I tried downgrading to WorkManager 2.7.1, which is the version that flutter_workmanagerv0.5.2 was using, and I think it has reverted the issue.

android/app/build.gradle

configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'androidx.work' && 
            (details.requested.name == 'work-runtime' || details.requested.name == 'work-runtime-ktx')) {
            details.useVersion '2.7.1'
        }
    }
}

I haven't tried upgrading (to 2.10.0), instead of downgrading, but it would be interesting to try. I'm not sure if this is something that is broken as well in the native WorkManager... or, instead (which would be bad news) something they have decided to patch so that there's no way around the 15 minutes limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      🐞Bug - initDelay in registerPeriodicTask is now useless · Issue #594 · fluttercommunity/flutter_workmanager