multi-tasks 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,7 +43,7 @@ multiTasks({
43
43
  processTask,
44
44
  multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files, you can check the progress here
45
45
  quotaOfEachTask:1, //The number of subtasks assigned to each worker at one time, the default is 1
46
- numberOfWorks: 6 //Assign how many workers are working in parallel
46
+ numberOfWorks: 6 //Assign how many workers are working in parallel, default is the number of cpu cores minus one
47
47
  });
48
48
 
49
49
  ```
@@ -71,6 +71,7 @@ node examples/example1/run
71
71
 
72
72
  Changelog:
73
73
 
74
+ - 1.2.4 Fix: opt.numberOfWorks not work
74
75
  - 1.2.3 Update README
75
76
  - 1.2.2 Update README and examples
76
77
  - 1.2.1 Handle exceptions and errors in subtasks
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "multi-tasks",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "example": "example"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "jest"
11
11
  },
12
12
  "keywords": [
13
13
  "multitask",
14
14
  "worker",
15
15
  "multithread"
16
16
  ],
17
- "dependencies": {
18
- },
19
17
  "author": "zhanglei923@gmail.com",
20
- "license": "MIT"
18
+ "license": "MIT",
19
+ "devDependencies": {
20
+ "jest": "^29.7.0"
21
+ }
21
22
  }
@@ -0,0 +1,17 @@
1
+ let splitter = require('../workers/taskSplitter');
2
+
3
+ let createArray = (len)=>{
4
+ let alltasks = []
5
+ for(let i=0;i<len;i++){
6
+ alltasks.push(i)
7
+ }
8
+ return alltasks;
9
+ }
10
+
11
+ test('test taskSplitter', async () => {
12
+
13
+ expect(splitter.split(createArray(3), 5).length).toBe(1);
14
+ expect(splitter.split(createArray(16), 5).length).toBe(4);
15
+ expect(splitter.split(createArray(101), 1).length).toBe(101);
16
+ expect(splitter.split(createArray(101), 33).length).toBe(4);
17
+ });
package/workers/master.js CHANGED
@@ -37,11 +37,11 @@ let hasWorker = ()=>{
37
37
  return workidlist.size !== 0;
38
38
  }
39
39
  let run = (currentProducer, currentConsumer, opt)=>{
40
- if(typeof opt === 'undefined') opt = {
41
- quotaOfEachTask: 10
42
- };
40
+ let defaultCPUs = numCPUs - 1;
41
+ if(typeof opt === 'undefined') opt = {};
43
42
  let masterId = currentProducer.getTaskName();
44
- if(typeof opt.numberOfWorks === 'undefined') opt.numberOfWorks = numCPUs;
43
+ if(typeof opt.quotaOfEachTask === 'undefined') opt.quotaOfEachTask = 1;
44
+ if(typeof opt.numberOfWorks === 'undefined') opt.numberOfWorks = defaultCPUs;
45
45
  console.log('master1, masterId=', masterId)
46
46
 
47
47
 
@@ -155,8 +155,7 @@ let start = (ProducerClass, ConsumerClass, taskConfig)=>{
155
155
  producer.setTaskTrunkInfo(taskConfig);
156
156
  consumer.setTaskTrunkInfo(taskConfig);
157
157
  run(producer, consumer, {
158
- quotaOfEachTask:2,
159
- numberOfWorks: 6
158
+ ...taskConfig
160
159
  });
161
160
  }
162
161
  module.exports = {