system-task
v1.0.1
Published
> Provide the basic task framework to help initial task implementation. It can be easy to inject any logging mechanism and integrate with any service framework.
Downloads
92
Readme
system-task
Provide the basic task framework to help initial task implementation. It can be easy to inject any logging mechanism and integrate with any service framework.
Contents
^Install
Install via npm:
npm install system-task --save
^Definition
const systemTask = require('system-task')
SystemTask
SystemTask is a base task engine, which handles to process all task items. It needs to overwritten by the following methods:
| Method | Description | Overriding Defination | |------------------------------|----------------------------------|------------------------------------------------| | insertPreprocessItemsHandler | Insert items for process | async insertPreprocessItemsHandler (task) | | preprocessHandler | Preprocess each item for process | async preprocessHandler (task, preProcessItem) | | processHandler | Execute each task item | async processHandler (task, processItem) | | cleanupHandler | Cleanup any processed task items | async cleanupHandler (task, cleanupItems) |
^Get Start
- Implement Custom Task
const SystemTask = require('system-task')
const TYPE = 'Demo Task'
const DEMOASSET = {
name: 'DEMO ASSET',
execute () {
console.log('Implement execute aseet logic')
}
}
const logMethod = function (messageType, message, detailMessage) {
console.log(messageType, message, detailMessage)
}
class DemoTask extends SystemTask {
const REQUIREASYNCEPROCESS = true
constructor () {
super(TYPE, REQUIREASYNCEPROCESS, logMethod)
}
async insertPreprocessItemsHandler (task) {
return [
{ Object.assign({}, DEMOASSET, { name: 'Asset 1' }) },
{ Object.assign({}, DEMOASSET, { name: 'Asset 2' }) }
]
}
async processHandler (task, processItem) {
await task.log('info', `execuse`, {Type: task.type, processItem})
// processItem can be execute method
// e.g. await processItem.execute()
return processItem
}
}
module.exports = DemoTask
- Start up Task
const DemoTask = require('./demoTask')
const task = new DemoTask()
task.start()
^License
MIT