restart timeout
This commit is contained in:
@@ -116,7 +116,7 @@ var UploadManager = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var i = 0; i < this.uploadThreads.length; i++) {
|
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;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
UploadWorker.prototype.start = function () {
|
UploadWorker.prototype.start = function () {
|
||||||
|
if (!this.uploading) {
|
||||||
|
this.newFile();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
UploadWorker.prototype.newFile = function () {
|
||||||
var file = this.manager.grabFile();
|
var file = this.manager.grabFile();
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
this.uploading = false;
|
this.uploading = false;
|
||||||
@@ -147,11 +152,6 @@ var UploadWorker = /** @class */ (function () {
|
|||||||
this.tries = 0;
|
this.tries = 0;
|
||||||
this.upload(file);
|
this.upload(file);
|
||||||
};
|
};
|
||||||
UploadWorker.prototype.startIfInactive = function () {
|
|
||||||
if (!this.uploading) {
|
|
||||||
this.start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
UploadWorker.prototype.upload = function (file) {
|
UploadWorker.prototype.upload = function (file) {
|
||||||
console.debug("Starting upload of " + file.file.name);
|
console.debug("Starting upload of " + file.file.name);
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
@@ -177,23 +177,21 @@ var UploadWorker = /** @class */ (function () {
|
|||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
file.onFinished(data.id);
|
file.onFinished(data.id);
|
||||||
console.log("Done: " + data.id);
|
|
||||||
that.setHistoryCookie(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) {
|
error: function (xhr, status, error) {
|
||||||
console.log(status);
|
console.log("status: " + status + " error: " + error);
|
||||||
console.log(error);
|
|
||||||
if (that.tries === 3) {
|
if (that.tries === 3) {
|
||||||
alert("Upload failed: " + status);
|
alert("Upload failed: " + status);
|
||||||
that.uploading = false;
|
|
||||||
file.onFailure(status, error);
|
file.onFailure(status, error);
|
||||||
that.start(); // Try to continue
|
setTimeout(that.newFile(), 2000); // Try to continue
|
||||||
return; // Upload failed
|
return; // Upload failed
|
||||||
}
|
}
|
||||||
// Try again
|
// Try again
|
||||||
that.tries++;
|
that.tries++;
|
||||||
that.upload(file);
|
setTimeout(that.upload(file), that.tries * 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@@ -21,7 +21,7 @@ class UploadManager {
|
|||||||
setTimeout(thread.start(), 0) // Start a new upload thread
|
setTimeout(thread.start(), 0) // Start a new upload thread
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < this.uploadThreads.length; i++) {
|
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) {
|
constructor(manager: UploadManager) {
|
||||||
this.manager = manager
|
this.manager = manager
|
||||||
}
|
}
|
||||||
|
public start(){
|
||||||
|
if (!this.uploading) {
|
||||||
|
this.newFile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public start() {
|
private newFile() {
|
||||||
var file = this.manager.grabFile()
|
var file = this.manager.grabFile()
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
this.uploading = false
|
this.uploading = false
|
||||||
@@ -55,11 +60,6 @@ class UploadWorker {
|
|||||||
this.tries = 0
|
this.tries = 0
|
||||||
this.upload(<FileUpload>file)
|
this.upload(<FileUpload>file)
|
||||||
}
|
}
|
||||||
public startIfInactive(){
|
|
||||||
if (!this.uploading) {
|
|
||||||
this.start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private upload(file: FileUpload){
|
private upload(file: FileUpload){
|
||||||
console.debug("Starting upload of " + file.file.name)
|
console.debug("Starting upload of " + file.file.name)
|
||||||
@@ -89,27 +89,25 @@ class UploadWorker {
|
|||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
file.onFinished(data.id)
|
file.onFinished(data.id)
|
||||||
console.log("Done: " + data.id)
|
|
||||||
that.setHistoryCookie(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){
|
error: function (xhr, status, error){
|
||||||
console.log(status)
|
console.log("status: "+status+" error: "+error)
|
||||||
console.log(error)
|
|
||||||
|
|
||||||
if (that.tries === 3) {
|
if (that.tries === 3) {
|
||||||
alert("Upload failed: " + status);
|
alert("Upload failed: " + status);
|
||||||
that.uploading = false
|
|
||||||
file.onFailure(status, error)
|
file.onFailure(status, error)
|
||||||
|
|
||||||
that.start() // Try to continue
|
setTimeout(that.newFile(), 2000) // Try to continue
|
||||||
return; // Upload failed
|
return; // Upload failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try again
|
// Try again
|
||||||
that.tries++
|
that.tries++
|
||||||
that.upload(file)
|
setTimeout(that.upload(file), that.tries*3000)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user