New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

task-hub

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

task-hub

Task-hub help you run and manage your schedule running function

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

task-hub

You know, task-hub help you run and manage your schedule running function.

NPM version

Installation

npm install task-hub

Quick start

const TaskHub = require('task-hub')

const taskHub = TaskHub.init()
const task = taskHub.addTask(function () {
  const { config } = this
  console.log(config.value)
  // 1
}, { value: 1 })
taskHub.start(task.id)

API

TaskHub.init()

Setup A Hub, this function will return the same instance even if you call multiple times.

addTask(function, options)

Add new task to hub

  • function: the task function
  • options: the config for task function
    • timeInterval: Time loop for task. Default is 5000
const taskConfig = {
  value: 1,
  timeInterval: 60000 // 1 minutes
}
const syncTask = function () {
  // You can access taskConfig from "this"
  const { config } = this
  console.log(config.value)
}
const asyncTask = function () {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log('Run')
      resolve()
    }, 3000)
  })
}
// add sync task
const task = taskHub.addTask(syncTask, taskConfig)
// add async task
const task = taskHub.addTask(asyncTask, taskConfig)

updateConfig(newConfig)

Update config of exist task in hub

  • newConfig: The config will be merged with exist config.
taskHub.updateConfig(task.id, {value: 2})

start(taskId)

Start the specific task in hub.

  • taskId: Id of task will be started.
taskHub.start(task.id)

stop(taskId)

Stop the specific task in hub.

  • taskId: Id of task will be stopped.
taskHub.stop(task.id)

stopAll()

Stop all task in hub.

taskHub.stopAll()

Note: If task is running, it can be stopped until it completes it's function

Events

start

Event when task start.

task.on('start', function () {
  console.log('Now, task will be executed.')
})

completed

Event when task run completed.

task.on('completed', function(res) {
  console.log('Result:', res)
})

error

Event when an error raised while execute task.

task.on('error', function(error) {
  console.log('An error has been occurred.', error)
})

Debug

To enable log of process, set

TaskHub.debug = true

Develop Path

  • Set limit for hub.
  • Limit quantity of tasks can be run at same time.
  • Stats for hub.

Keywords

task

FAQs

Package last updated on 22 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts