mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 22:28:41 +00:00
fix #174
This commit is contained in:
parent
c53736566b
commit
b6502ca8d0
1 changed files with 15 additions and 10 deletions
|
|
@ -82,19 +82,25 @@ Future sendMediaFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future retryMediaUpload() async {
|
|
||||||
final mediaFiles =
|
|
||||||
await twonlyDatabase.mediaUploadsDao.getMediaUploadsForRetry();
|
|
||||||
for (final mediaFile in mediaFiles) {
|
|
||||||
await handleSingleMediaFile(mediaFile.mediaUploadId, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final lockingHandleMediaFile = Mutex();
|
final lockingHandleMediaFile = Mutex();
|
||||||
|
Future retryMediaUpload({int maxRetries = 3}) async {
|
||||||
|
await lockingHandleMediaFile.protect(() async {
|
||||||
|
final mediaFiles =
|
||||||
|
await twonlyDatabase.mediaUploadsDao.getMediaUploadsForRetry();
|
||||||
|
if (mediaFiles.isEmpty) return;
|
||||||
|
for (final mediaFile in mediaFiles) {
|
||||||
|
await handleSingleMediaFile(mediaFile.mediaUploadId, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (maxRetries == 0) return;
|
||||||
|
// retry upload
|
||||||
|
Future.delayed(const Duration(milliseconds: 1000), () {
|
||||||
|
retryMediaUpload(maxRetries: maxRetries - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future handleSingleMediaFile(
|
Future handleSingleMediaFile(
|
||||||
int mediaUploadId, Uint8List? tmpCurrentImageBytes) async {
|
int mediaUploadId, Uint8List? tmpCurrentImageBytes) async {
|
||||||
// await lockingHandleMediaFile.protect(() async {
|
|
||||||
MediaUpload? media = await twonlyDatabase.mediaUploadsDao
|
MediaUpload? media = await twonlyDatabase.mediaUploadsDao
|
||||||
.getMediaUploadById(mediaUploadId)
|
.getMediaUploadById(mediaUploadId)
|
||||||
.getSingleOrNull();
|
.getSingleOrNull();
|
||||||
|
|
@ -156,7 +162,6 @@ Future handleSingleMediaFile(
|
||||||
.shout("Non recoverable error while sending media file: $e");
|
.shout("Non recoverable error while sending media file: $e");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// });
|
|
||||||
// this will be called until there is an recoverable error OR
|
// this will be called until there is an recoverable error OR
|
||||||
// the upload is ready
|
// the upload is ready
|
||||||
await handleSingleMediaFile(mediaUploadId, tmpCurrentImageBytes);
|
await handleSingleMediaFile(mediaUploadId, tmpCurrentImageBytes);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue