system-task
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/system-task package

1.0.1 • Public • Published

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


InstallDefinitionGet StartLicense


^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

Readme

Keywords

none

Package Sidebar

Install

npm i system-task

Weekly Downloads

17

Version

1.0.1

License

MIT

Unpacked Size

12.1 kB

Total Files

6

Last publish

Collaborators

  • llam