1.0.1 • Published 5 years ago

system-task v1.0.1

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

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.

License Build Status Coverage Status Dependency Status devDependency Status semantic-release JavaScript Style Guide Greenkeeper badge npm badge

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:

MethodDescriptionOverriding Defination
insertPreprocessItemsHandlerInsert items for processasync insertPreprocessItemsHandler (task)
preprocessHandlerPreprocess each item for processasync preprocessHandler (task, preProcessItem)
processHandlerExecute each task itemasync processHandler (task, processItem)
cleanupHandlerCleanup any processed task itemsasync 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