mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-10-14 11:41:07 +02:00
I literally forget. Removed some debugs.
This commit is contained in:
1 parent
868e6cb7f7
commit
58ecf550a5
1 file changed
+8
-6
@@ -484,24 +484,26 @@ for (int z = zMin; z <= zMax; z++) {
|
|||||||
if (await file.exists()) return; // already downloaded
|
if (await file.exists()) return; // already downloaded
|
||||||
const int maxAttempts = 3;
|
const int maxAttempts = 3;
|
||||||
int attempt = 0;
|
int attempt = 0;
|
||||||
int delayMs = 500;
|
final random = Random();
|
||||||
|
// Backoff schedule in ms: 0 (immediate), 3000±500 (3s+/-), 10000±2000 (10s+/-)
|
||||||
|
final delays = [0, 3000 + random.nextInt(1000) - 500, 10000 + random.nextInt(4000) - 2000];
|
||||||
while (true) {
|
while (true) {
|
||||||
attempt++;
|
|
||||||
try {
|
try {
|
||||||
|
attempt++;
|
||||||
final resp = await http.get(Uri.parse(url));
|
final resp = await http.get(Uri.parse(url));
|
||||||
if (resp.statusCode == 200) {
|
if (resp.statusCode == 200) {
|
||||||
await file.writeAsBytes(resp.bodyBytes);
|
await file.writeAsBytes(resp.bodyBytes);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to download tile $z/$x/$y (status ${resp.statusCode})');
|
throw Exception('Failed to download tile $z/$x/$y (status \\${resp.statusCode})');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (attempt >= maxAttempts) {
|
if (attempt >= maxAttempts) {
|
||||||
throw Exception('Failed to download tile $z/$x/$y after $attempt attempts: $e');
|
throw Exception('Failed to download tile $z/$x/$y after $attempt attempts: $e');
|
||||||
}
|
}
|
||||||
debugPrint('Retrying tile $z/$x/$y after failure (attempt $attempt): $e');
|
final delay = delays[attempt-1].clamp(0, 60000);
|
||||||
await Future.delayed(Duration(milliseconds: delayMs));
|
debugPrint('Retrying tile $z/$x/$y after failure (attempt $attempt, delaying \\${delay}ms): $e');
|
||||||
delayMs *= 2;
|
await Future.delayed(Duration(milliseconds: delay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user