diff --git a/lib/task.js b/lib/task.js index 763c45f..a388991 100644 --- a/lib/task.js +++ b/lib/task.js @@ -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); }