gitlab:https://github.com/DoTalkLily/TaskManager
task manager
This is a task manager framework in js. It provides you with an executor for a bunch of tasks and manage the lifecycle of your task, you could subscribe the lifecycle event. Task could be an calculation which takes a long time,or an mission which should be executed periodically.
how to use
You could include the task-manager.js under directory 'dest/' in your html.Like:
<script type="text/javascript" src="/your_directory/task-manager.js"></script>
If you modified the source code and rebuild it, you need webpack installed globally:
$ npm install --save webpack
Then execute under root directory:
$ webpack
Task
- create a task
sh var taskManager = new TaskManager(); taskManager.createTask({ id : taskId, run : function(){ //process code goes here } });
-
subscribe a topic
var token = PubSub.subscribe(taskId,handler);
'handler' is the function to process result when the task manager publish some result to the topic. e.g.
function handler(topic, res) { }
The 'topic' is the topic you subscribed, 'res' is the data received.
An unique token is returned to unsubscribe the topic.
var token = PubSub.unsubscribe(token);
Then a task is created and add to the task manager.To start is,you could call 'start'. e.g.
taskManager.runTask(taskId);
Then you could leave it behind and process other code.
-
Configurations
-
interval(optional,unit: millisecond)
It defines how often the 'run' method of the task is executed. Default is 10000.
-
init (optional,function)
Some initialization before running the task,it could return a promise , 'run' method is executed after the promise resolved.
-
run (required,function)
The main job of this task, which could send http request to server(ajax),or an time consuming calculation, etc. After the user defined processing is done, task manager will publish the result to the specific taskId. Your 'handler'(metioned above) will receive the result(if exists) then decide to kill the task or repeat the task after 'interval'(metioned above) time.
It could return a promise, then the publish action will take after the promise is resolved(It's useful when you are sending some ajax request).
-
kill (optional,function)
-
If is provided, it could be some work before killing an task.
-
Api of a single task
-
createTask
Create a single task.The configuration of a task is passed.Including:
- interval(optional):interval of executing a task
- id (required):unique id of the task
- run(required): task mission
- kill(optional): kill mission
return : The task just created.
-
createTaskList
Create a list of tasks. The configuration of the task list is passed. Including:
- interval(optional):interval of executing a task
- ids (required):list of id of the task
- init(optional): init work before executing the task
- run(required): task mission
- kill(optional): kill mission return : The list of tasks just created.
-
runTask
Start to run the task.The task id is passed.
taskManager.runTask(taskId);
-
runTaskList
Start to run the task list at the same time .Array of task ids is passed.
taskManager.runTask([taskid1,taskid2]);
-
pauseTask
Pause a task. Task id is required.
taskManager.pauseTask(taskId);
-
pauseTaskList
Pause a list of tasks at the same time.Array of task ids is required.
taskManager.pauseTaskList([taskId1,taskId2]);
-
continueTask
Wake up the task which is paused. Task id is required.
taskManager.continueTask(taskId);
-
continueTaskList
Wake up the task which is paused.Array of task ids is required.
taskManager.continueTaskList([taskId1,taskId2]);
-
killTask
Kill the task. Task id is required.
taskManager.killTask(taskId);
-
killTaskList
Kill a list of tasks at the same time. Array of task ids is required.
taskManager.killTaskList([taskId1,taskId2]);
-
Batch Task
There is a condition when serveral tasks share one execution method.
- Task manager collects the 'batchParam' of each task in the task queue. The 'batchParam' is defined when creating a batch task,which is the data each specific task may need when batch process taking place.
- Then execution shared by the batch tasks is called.
- Results are dispatched(published) to each batch task according to their task id.
- Each task may decide if it would attend next execution period or remove itself from the task queue according to the result they got(subscribe);
- After the 'interval' time, the task manager will repeat the same process again until there is no task in the task queue.
-
Api of a batch task
-
createBatchTask
- option
- id (required) : id of the task,should be unique!
- init (function,optional): init task
- afterInit(function,optional): callback of init
- callback(function,optional): callback of each response result(you may also subscribe the result)
taskManager.createBatchTask({ id: taskId, batchParams:{ //params for this task during execution } });
- option
-
killBatchTask
- option
- id (required) : id of the task
- kill(function,optional): function before the task is killed
taskManager.killBatchTask({ id: taskId }); //or you may just pass the task id taskManager.killBatchTask(taskId);
- option
-
相关推荐
本源码项目是基于Java的分布式任务调度框架设计,包含1201个文件,主要使用Java、CSS、JavaScript和Shell编程语言。该项目是一个分布式任务调度框架,旨在帮助开发者更高效地管理和调度任务。系统提供了实时任务、...
基于JavaScript的动态权限控制任务调度系统源码+运行说明.zip基于JavaScript的动态权限控制任务调度系统源码+运行说明.zip基于JavaScript的动态权限控制任务调度系统源码+运行说明.zip基于JavaScript的动态权限控制...
JavaScript手写发布订阅
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、...基于JavaScript的电梯调度模拟器源码.zip
基于JavaScript的项目框架模板
javaScript发布订阅模式代码实现思路,有平台,发布者,订阅者
基于JavaScript实现进程调度算法模拟_源码
Open MCT:一个基于web的任务控制框架
danceUI是一个基于Javascript的前端框架,包含132个文件,其中包括52个HTML文件、49个PNG图片文件、11个JavaScript文件、10个DS_Store文件、4个CSS文件、3个SVG文件、2个JPG图片文件和1个Markdown文件。该项目适用于...
基于JavaScript切片的AJAX框架网络爬虫技术研究.pdf基于JavaScript切片的AJAX框架网络爬虫技术研究.pdf基于JavaScript切片的AJAX框架网络爬虫技术研究.pdf
Hodor是一款基于Java开发的分布式任务调度系统,专注于任务编排和高可用性。该项目包含1055个文件,其中包括728个Java源文件、73个XML文件、67个Vue文件、58个JavaScript文件、38个Properties文件、16个Less文件、10...
本项目是基于Javascript的mpvue小程序开发框架设计源码,包含512个文件,其中包括424个JavaScript文件、17个Markdown文档、16个HTML文件、13个JSON文件、11个TypeScript文件、9个CSS文件、7个eslintrc文件、3个YAML...
便于二次开发的低成本的定时任务调度与管理系统.zip 当你拥有足够复杂的业务...系统本身是基于swoole实现,并且自身不处理业务逻辑只负责任务的调度和管理,每个任务可设置多样化的周期执行时间和调度方式异步运行。
本项目是基于Javascript的小游戏框架设计源码,包含295个文件,其中包括113个JSON文件、83个JavaScript文件、38个Meta文件、23个PNG图片文件、18个TypeScript文件、10个MP3文件、3个Markdown文档、2个gitignore文件...
本项目是一个基于JavaScript和TypeScript的Fastify Web框架设计源码,包含228个文件,其中134个JavaScript文件、34个Markdown文件、29个TypeScript文件、9个YAML文件、5个MJS文件、3个JSON文件、1个Editorconfig文件...
xxl-job是一个基于Java开发的分布式任务调度平台,包含287个文件,其中包括133个Java源文件、35个PNG图片文件、35个JavaScript文件、16个XML文件、12个CSS文件、11个FTL模板文件、6个Properties配置文件、3个...
xxl-job是一个基于Java开发的定时任务调度系统,包含287个文件,其中包括135个Java源文件、35个PNG图片文件、35个JavaScript文件、16个XML文件、12个CSS文件、11个FTL模板文件、5个Markdown文件、4个Properties文件...
基于Javascript原型的Zepto框架设计.pdf
基于JavaScript的地理事件可视分析框架设计.pdf
这是一个基于Java的惊讶网站统一调度任务平台设计,包含193个文件。主要文件类型包括116个Java源文件、27个JSP文件、11个XML文件、8个JavaScript文件、5个CSS文件、3个Shell脚本文件、3个TLD文件、2个map文件、2个...