restart timeout

This commit is contained in:
2018-01-17 11:02:12 +01:00
parent 31a25a50b5
commit 4957ef5552
2 changed files with 23 additions and 27 deletions

View File

@@ -116,7 +116,7 @@ var UploadManager = /** @class */ (function () {
}
else {
for (var i = 0; i < this.uploadThreads.length; i++) {
this.uploadThreads[i].startIfInactive();
setTimeout(this.uploadThreads[i].start(), 0);
}
}
};
@@ -137,6 +137,11 @@ var UploadWorker = /** @class */ (function () {
this.manager = manager;
}
UploadWorker.prototype.start = function () {
if (!this.uploading) {
this.newFile();
}
};
UploadWorker.prototype.newFile = function () {
var file = this.manager.grabFile();
if (file === undefined) {
this.uploading = false;
@@ -147,11 +152,6 @@ var UploadWorker = /** @class */ (function () {
this.tries = 0;
this.upload(file);
};
UploadWorker.prototype.startIfInactive = function () {
if (!this.uploading) {
this.start();
}
};
UploadWorker.prototype.upload = function (file) {
console.debug("Starting upload of " + file.file.name);
var formData = new FormData();
@@ -177,23 +177,21 @@ var UploadWorker = /** @class */ (function () {
},
success: function (data) {
file.onFinished(data.id);
console.log("Done: " + data.id);
that.setHistoryCookie(data.id);
that.start(); // Continue uploading on this thread
console.log("Done: " + data.id);
that.newFile(); // Continue uploading on this thread
},
error: function (xhr, status, error) {
console.log(status);
console.log(error);
console.log("status: " + status + " error: " + error);
if (that.tries === 3) {
alert("Upload failed: " + status);
that.uploading = false;
file.onFailure(status, error);
that.start(); // Try to continue
setTimeout(that.newFile(), 2000); // Try to continue
return; // Upload failed
}
// Try again
that.tries++;
that.upload(file);
setTimeout(that.upload(file), that.tries * 3000);
}
});
};

View File

@@ -21,7 +21,7 @@ class UploadManager {
setTimeout(thread.start(), 0) // Start a new upload thread
} else {
for (var i = 0; i < this.uploadThreads.length; i++) {
this.uploadThreads[i].startIfInactive()
setTimeout(this.uploadThreads[i].start(), 0)
}
}
}
@@ -42,8 +42,13 @@ class UploadWorker {
constructor(manager: UploadManager) {
this.manager = manager
}
public start(){
if (!this.uploading) {
this.newFile()
}
}
public start() {
private newFile() {
var file = this.manager.grabFile()
if (file === undefined) {
this.uploading = false
@@ -55,11 +60,6 @@ class UploadWorker {
this.tries = 0
this.upload(<FileUpload>file)
}
public startIfInactive(){
if (!this.uploading) {
this.start()
}
}
private upload(file: FileUpload){
console.debug("Starting upload of " + file.file.name)
@@ -89,27 +89,25 @@ class UploadWorker {
},
success: function (data) {
file.onFinished(data.id)
console.log("Done: " + data.id)
that.setHistoryCookie(data.id)
console.log("Done: " + data.id)
that.start() // Continue uploading on this thread
that.newFile() // Continue uploading on this thread
},
error: function (xhr, status, error){
console.log(status)
console.log(error)
console.log("status: "+status+" error: "+error)
if (that.tries === 3) {
alert("Upload failed: " + status);
that.uploading = false
file.onFailure(status, error)
that.start() // Try to continue
setTimeout(that.newFile(), 2000) // Try to continue
return; // Upload failed
}
// Try again
that.tries++
that.upload(file)
setTimeout(that.upload(file), that.tries*3000)
}
});
}