Issue with WorkManager Periodic Task Scheduling
shubham0809200 opened this issue · comments
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:
- The periodic task was initially scheduled for execution at 1:00 AM. which went well
- I turned off the network connection until 4:00 AM, causing the task to miss its scheduled execution at 3:00 AM
- Due to the unavailability of the network, the task was executed later than expected, at 4:00 AM.
- 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),
);