akyuu-schedule
Advanced tools
Comparing version 0.1.1 to 0.1.2
34
index.js
@@ -14,7 +14,26 @@ /** | ||
this.akyuu = akyuu; | ||
this.logger = akyuu.logger.get('plugin-schedule'); | ||
this.position = this.akyuu.PLUGIN_POS.AFTER_CONTROLLER; | ||
this.mode = options.mode; | ||
this.disabledTasks = options.disabledTasks || []; | ||
this.enabledTasks = options.enabledTasks || []; | ||
} | ||
_isEnabled(name) { | ||
const mode = this.mode; | ||
const disabledTasks = this.disabledTasks; | ||
const enabledTasks = this.enabledTasks; | ||
if(mode === 'blacklist') { | ||
return disabledTasks.indexOf(name) < 0; | ||
} else if(mode === 'whiteList') { | ||
return enabledTasks.indexOf(name) > -1; | ||
} else { | ||
return true; | ||
} | ||
} | ||
plug() { | ||
const dir = path.join(this.akyuu.config.server.root, 'scheduled'); | ||
const _this = this; | ||
const dir = path.join(_this.akyuu.config.server.root, 'scheduled'); | ||
let fileList = []; | ||
@@ -43,7 +62,16 @@ try { | ||
schedule.scheduleJob(task.plan, task.job); | ||
if (!_this._isEnabled(path.parse(file).name)) continue; | ||
schedule.scheduleJob(task.plan, function() { | ||
task.job(function(error) { | ||
if(error) { | ||
_this.logger.error('run schedule job error'); | ||
_this.logger.error(error.stack); | ||
} | ||
}); | ||
}); | ||
} | ||
if(fileList.length === 0) { | ||
console.log('no task'); | ||
_this.logger.info('no schedule job'); | ||
} | ||
@@ -50,0 +78,0 @@ } |
{ | ||
"name": "akyuu-schedule", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "schedule plug in for akyuu", | ||
@@ -25,2 +25,2 @@ "main": "index.js", | ||
} | ||
} | ||
} |
3554
68