mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 21:19:28 +02:00
Bugfix: BG update fail leads to infinite retries (#838)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
|
import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
|
||||||
import 'package:android_intent_plus/flag.dart';
|
import 'package:android_intent_plus/flag.dart';
|
||||||
@@ -116,16 +117,19 @@ moveStrToEnd(List<String> arr, String str, {String? strB}) {
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveStrToEndMapEntryWithCount(
|
List<MapEntry<String, int>> moveStrToEndMapEntryWithCount(
|
||||||
List<MapEntry<String, int>> arr, MapEntry<String, int> str,
|
List<MapEntry<String, int>> arr, MapEntry<String, int> str,
|
||||||
{MapEntry<String, int>? strB}) {
|
{MapEntry<String, int>? strB}) {
|
||||||
MapEntry<String, int>? temp;
|
MapEntry<String, int>? temp;
|
||||||
arr.removeWhere((element) {
|
arr.removeWhere((element) {
|
||||||
bool res = element.key == str.key || element.key == strB?.key;
|
bool resA = element.key == str.key;
|
||||||
if (res) {
|
bool resB = element.key == strB?.key;
|
||||||
temp = element;
|
if (resA) {
|
||||||
|
temp = str;
|
||||||
|
} else if (resB) {
|
||||||
|
temp = strB;
|
||||||
}
|
}
|
||||||
return res;
|
return resA || resB;
|
||||||
});
|
});
|
||||||
if (temp != null) {
|
if (temp != null) {
|
||||||
arr = [...arr, temp!];
|
arr = [...arr, temp!];
|
||||||
@@ -1338,7 +1342,7 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
|||||||
try {
|
try {
|
||||||
for (int i = 0; i < toCheck.length; i++) {
|
for (int i = 0; i < toCheck.length; i++) {
|
||||||
var appId = toCheck[i].key;
|
var appId = toCheck[i].key;
|
||||||
var retryCount = toCheck[i].value;
|
var attemptCount = toCheck[i].value + 1;
|
||||||
AppInMemory? app = appsProvider.apps[appId];
|
AppInMemory? app = appsProvider.apps[appId];
|
||||||
if (app?.app.installedVersion != null) {
|
if (app?.app.installedVersion != null) {
|
||||||
try {
|
try {
|
||||||
@@ -1362,16 +1366,16 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
|||||||
// If you got an error, move the offender to the back of the line (increment their fail count) and schedule another task to continue checking shortly
|
// If you got an error, move the offender to the back of the line (increment their fail count) and schedule another task to continue checking shortly
|
||||||
logs.add(
|
logs.add(
|
||||||
'BG update task $taskId: Got error on checking for $appId \'${e.toString()}\'.');
|
'BG update task $taskId: Got error on checking for $appId \'${e.toString()}\'.');
|
||||||
if (retryCount < maxAttempts) {
|
if (attemptCount < maxAttempts) {
|
||||||
var remainingSeconds = e is RateLimitError
|
var remainingSeconds = e is RateLimitError
|
||||||
? (i == 0 ? (e.remainingMinutes * 60) : (5 * 60))
|
? (i == 0 ? (e.remainingMinutes * 60) : (5 * 60))
|
||||||
: e is ClientException
|
: e is ClientException
|
||||||
? (15 * 60)
|
? (15 * 60)
|
||||||
: (retryCount ^ 2);
|
: pow(attemptCount, 2).toInt();
|
||||||
logs.add(
|
logs.add(
|
||||||
'BG update task $taskId: Will continue in $remainingSeconds seconds (with $appId moved to the end of the line).');
|
'BG update task $taskId: Will continue in $remainingSeconds seconds (with $appId moved to the end of the line).');
|
||||||
var remainingToCheck = moveStrToEndMapEntryWithCount(
|
var remainingToCheck = moveStrToEndMapEntryWithCount(
|
||||||
toCheck.sublist(i), MapEntry(appId, retryCount + 1));
|
toCheck.sublist(i), MapEntry(appId, attemptCount));
|
||||||
AndroidAlarmManager.oneShot(Duration(seconds: remainingSeconds),
|
AndroidAlarmManager.oneShot(Duration(seconds: remainingSeconds),
|
||||||
taskId + 1, bgUpdateCheck,
|
taskId + 1, bgUpdateCheck,
|
||||||
params: {
|
params: {
|
||||||
|
Reference in New Issue
Block a user