Improve Logic for Handelling Interrupted Downloads
continuous-integration/drone/pr Build is passing Details

Move logic into FileDownloadProgress model, simplify to
the lastUpdated cases which abstracts over the requested case.
This commit is contained in:
Sarah Jamie Lewis 2024-01-04 11:52:02 -08:00
parent cc8227d228
commit abd7fe7415
2 changed files with 12 additions and 15 deletions

View File

@ -3,12 +3,22 @@ class FileDownloadProgress {
int chunksTotal = 1;
bool complete = false;
bool gotManifest = false;
bool interrupted = false;
bool _interrupted = false;
// we keep track of both an explicit interrupt flag (for when a request fails or is explicitly cancelled)
set interrupted(isInterrupted) {
this._interrupted = isInterrupted;
}
// but we have a fuzzy get which depends on lastUpdate, if the file isn't complete, but the last update was more
// that 30 seconds ago, we consider this download as failed.
get interrupted => _interrupted || (DateTime.now().difference(lastUpdate).abs().inSeconds > 30 && !complete);
String? downloadedTo;
DateTime? timeStart;
DateTime? timeEnd;
DateTime? requested;
DateTime lastUpdate = DateTime.now();
DateTime lastUpdate = DateTime.fromMillisecondsSinceEpoch(0);
FileDownloadProgress(this.chunksTotal, this.timeStart);

View File

@ -383,19 +383,6 @@ class ProfileInfoState extends ChangeNotifier {
if (this._downloads[fileKey]!.interrupted) {
return true;
}
if (this._downloads[fileKey]!.requested != null) {
if (DateTime.now().difference(this._downloads[fileKey]!.requested!) > Duration(minutes: 1)) {
this._downloads[fileKey]!.requested = null;
this._downloads[fileKey]!.interrupted = true;
return true;
}
if (DateTime.now().difference(this._downloads[fileKey]!.lastUpdate) > Duration(minutes: 1)) {
this._downloads[fileKey]!.requested = null;
this._downloads[fileKey]!.interrupted = true;
return true;
}
}
}
return false;
}