Clear upload queue with a reason

This commit is contained in:
Vishnu Mohandas 2021-02-25 21:44:27 +05:30
parent 8dfa777db3
commit a0614ad114
2 changed files with 12 additions and 10 deletions

View file

@ -44,7 +44,7 @@ class SyncService {
SyncService._privateConstructor() {
Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
_uploader.clearQueue();
_uploader.clearQueue(SyncStopRequestedError());
sync();
});

View file

@ -116,7 +116,7 @@ class FileUploader {
}
}
void clearQueue() {
void clearQueue(final Error reason) {
final uploadsToBeRemoved = List<int>();
_queue.entries
.where((entry) => entry.value.status == UploadStatus.not_started)
@ -124,13 +124,13 @@ class FileUploader {
uploadsToBeRemoved.add(pendingUpload.key);
});
for (final id in uploadsToBeRemoved) {
_queue.remove(id).completer.completeError(SyncStopRequestedError());
_queue.remove(id).completer.completeError(reason);
}
}
void _pollQueue() {
if (SyncService.instance.shouldStopSync()) {
clearQueue();
clearQueue(SyncStopRequestedError());
}
if (_queue.length > 0 && _currentlyUploading < kMaximumConcurrentUploads) {
final firstPendingEntry = _queue.entries
@ -434,10 +434,12 @@ class FileUploader {
.toList();
_uploadURLs.addAll(urls);
} on DioError catch (e) {
if (e.response.statusCode == 402) {
_onExpiredSubscription();
} else if (e.response.statusCode == 426) {
_onStorageLimitExceeded();
if (e.response != null) {
if (e.response.statusCode == 402) {
_onExpiredSubscription();
} else if (e.response.statusCode == 426) {
_onStorageLimitExceeded();
}
}
throw e;
}
@ -448,12 +450,12 @@ class FileUploader {
}
void _onStorageLimitExceeded() {
clearQueue();
clearQueue(StorageLimitExceededError());
throw StorageLimitExceededError();
}
void _onExpiredSubscription() {
clearQueue();
clearQueue(NoActiveSubscriptionError());
throw NoActiveSubscriptionError();
}