Update task.js

This commit is contained in:
Namhyeon Go 2021-07-20 03:09:24 +09:00 committed by GitHub
parent 19957e12b7
commit 939121321e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,13 +20,19 @@ var Task = function(f, params) {
this.f = f;
this.params = params;
this.nextTask = null;
this.failTask = null;
this.when = 0;
this.delay = 0;
this.callCount = 0;
this.setNextTask = function(task) {
this.nextTask = task;
return this;
};
this.setFailTask = function(task) {
this.failTask = task;
return this;
};
this.setWhen = function(when) {
this.when = when;
return this;
@ -41,6 +47,7 @@ var Task = function(f, params) {
};
this.resetCount = function() {
this.callCount = 0;
return this;
};
};
@ -48,6 +55,7 @@ var TaskQueue = function() {
this._task = null;
this._keepalive = true;
this.queue = [];
this.put = function(task, delay) {
var now = new Date();
@ -102,6 +110,11 @@ var TaskQueue = function() {
console.error("Task exception: " + e.message);
console.error("task.f: " + typeof(task.f));
console.error("task.params: " + typeof(task.params));
// 태스크 개별 오류 처리
if (task.failTask) {
this.put(task.failTask, 0);
}
}
}
} catch(e) {
@ -139,9 +152,9 @@ exports.createTaskQueue = function() {
return new TaskQueue();
};
exports.createTask = function(f, params) {
exports.createTask = function(f, params, failTask) {
try {
return new Task(f, params);
return (new Task(f, params)).setFailTask(failTask);
} catch(e) {
console.error("createTask exception: " + e.message);
}