Skip to content
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

Issue with WorkManager Periodic Task Scheduling #538

Open
shubham0809200 opened this issue Feb 19, 2024 · 1 comment
Open

Issue with WorkManager Periodic Task Scheduling #538

shubham0809200 opened this issue Feb 19, 2024 · 1 comment

Comments

@shubham0809200
Copy link

Issue with WorkManager Periodic Task Scheduling

Description

I encountered an issue with WorkManager while scheduling a periodic task with a 2-hour interval and a constraint that the network should be available. Here's the scenario:

  1. The periodic task was initially scheduled for execution at 1:00 AM. which went well
  2. I turned off the network connection until 4:00 AM, causing the task to miss its scheduled execution at 3:00 AM
  3. Due to the unavailability of the network, the task was executed later than expected, at 4:00 AM.
  4. Subsequently, instead of maintaining the 2-hour interval from the last executed task, the next execution occurred at 6:00 AM.

Expected Behavior

The periodic task should maintain its scheduled interval of 2 hours, irrespective of delays caused by network unavailability. In the scenario described above, the task should have been executed at 3:00 AM and then at 5:00 AM, as per the scheduled interval.

I understand the scenario of why it wasn't able to run at 3:00 AM but it should have gone off at 5:00 AM as per its schedule.

I have provided my code for reference the the end of this issue.

Note: If there are any available solutions or recommendations to address this scenario, I would greatly appreciate any assistance or guidance provided. Thank you.

CODE

Workmanager().registerPeriodicTask(
  "backupData",
  "backupData",
  frequency: Duration(hours: 2),
  initialDelay: timeDuration,
  constraints: Constraints(
    networkType: NetworkType.connected,
  ),
  backoffPolicy: BackoffPolicy.linear,
  existingWorkPolicy: ExistingWorkPolicy.replace,
  outOfQuotaPolicy: OutOfQuotaPolicy.run_as_non_expedited_work_request,
  backoffPolicyDelay: Duration(seconds: 10),
);
@prabhakar1992
Copy link

@ened I have also got an issue in workmanager, periodic task not triggered when app is in killed state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants