task-hub
You know, task-hub help you run and manage your schedule running function.
Installation
npm install task-hub
Quick start
const TaskHub = const taskHub = TaskHubconst task = taskHubtaskHubstarttaskid
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 minutesconst syncTask = { // You can access taskConfig from "this" const config = this console}const asyncTask = { return { }}// add sync taskconst task = taskHub// add async taskconst task = taskHub
updateConfig(newConfig)
Update config of exist task in hub
- newConfig: The config will be merged with exist config.
taskHub
start(taskId)
Start the specific task in hub.
- taskId: Id of task will be started.
taskHubstarttaskid
stop(taskId)
Stop the specific task in hub.
- taskId: Id of task will be stopped.
taskHub
stopAll()
Stop all task in hub.
taskHub
Note: If task is running, it can be stopped until it completes it's function
Events
start
Event when task start.
task
completed
Event when task run completed.
task
error
Event when an error raised while execute task.
task
Debug
To enable log of process, set
TaskHubdebug = true
Develop Path
- Set limit for hub.
- Limit quantity of tasks can be run at same time.
- Stats for hub.