multi-tasks 2.0.0 → 2.0.1

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
@@ -113,6 +113,7 @@ node examples/example1/run
113
113
 
114
114
  Changelog:
115
115
 
116
+ - 2.0.1 Avoid possible I/O conflicts.
116
117
  - 2.0.0 Rewritten with a new architecture to support dynamic tasks.
117
118
  - 1.2.8 Fix: create task folder failed on MacOS
118
119
  - 1.2.7 Small updates
@@ -46,7 +46,7 @@ multiTasks({
46
46
  taskRootFolder: `../examples-tmp-data/example0`, //a directory to store progress and results files, you can check the progress here
47
47
  taskId: 'my-task',
48
48
  numberOfWorkers: 3, //Assign how many workers are working in parallel
49
- //autoCloseAfterCompletion: true,
49
+ autoCloseAfterCompletion: true,
50
50
  onFinish: (report)=>{
51
51
  console.log('finish callback', report);
52
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-tasks",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utils/makedir.js CHANGED
@@ -39,14 +39,10 @@ function getDirectFiles(dir, callback) {
39
39
  files.forEach(file => {
40
40
  const filePath = path.join(dir, file);
41
41
  //console.log(filePath)
42
- try{
43
42
  let stats = fs.statSync(filePath);
44
43
  if (stats.isFile()) {
45
44
  childrenfiles.push(file);
46
45
  }
47
- }catch(e){
48
- //
49
- }
50
46
  });
51
47
  callback(childrenfiles);
52
48
  });
@@ -53,9 +53,11 @@ const start = (config)=>{
53
53
  WorkerMgr.addWorker(worker);
54
54
  worker.on('message', function(message) {
55
55
  if(message === MSG_REQUEST_NEW_TASK){
56
- queue.enqueue(TaskMgr.updateNewTasks);//use queue to make sure no I/O conflict
56
+ queue.enqueue(async ()=>{
57
+ return TaskMgr.updateNewTasks();
58
+ });//use queue to make sure no I/O conflict
57
59
  queue.enqueue(async () => {
58
- TaskMgr.popNewTask().then((subTask)=>{
60
+ return TaskMgr.popNewTask().then((subTask)=>{
59
61
  if(!subTask){
60
62
  //no tasks left
61
63
  console.log('[Master]: no tasks left!');
@@ -99,7 +101,7 @@ const start = (config)=>{
99
101
  setTimeout(()=>{
100
102
  console.log('[Master]: all workers are done, process exit.')
101
103
  process.exit(0);
102
- }, 1000);
104
+ }, 10);
103
105
  }
104
106
  });
105
107
  }else{
@@ -95,15 +95,13 @@ const TaskMgr = {
95
95
  loadNewTasks:()=>{
96
96
  const {masterTaskId, taskFolderNew} = main_config;
97
97
  return new Promise((resolve)=>{
98
+ console.log('get1')
98
99
  makeDir.getDirectFiles(taskFolderNew, (taskFiles)=>{
99
100
  taskFiles.forEach((filename)=>{
100
101
  let fpath = pathutil.resolve(taskFolderNew, filename);
101
102
  let fcontent;
102
- try{
103
103
  fcontent = fs.readFileSync(fpath, 'utf-8');
104
- }catch(e){
105
- console.log('[WARN]', `file not found`, fpath)
106
- }
104
+
107
105
  if(fcontent){
108
106
  let task = JSON.parse(fcontent);
109
107
  allSubTasks.new.push(task);
@@ -152,6 +150,7 @@ const TaskMgr = {
152
150
  getTaskFiles:(type, callback)=>{
153
151
  let rootdir = main_config.progressRootFolder;
154
152
  let targetFolder = pathutil.resolve(rootdir, `./${type}`);
153
+ console.log('get2')
155
154
  makeDir.getDirectFiles(targetFolder, (files)=>{
156
155
  callback(files);
157
156
  });
@@ -161,14 +160,11 @@ const TaskMgr = {
161
160
  let {progressRootFolder} = main_config;
162
161
  let oldPath = pathutil.resolve(progressRootFolder, `./${from}/${subid}.task.json`);
163
162
  let newPath = pathutil.resolve(progressRootFolder, `./${to}/${subid}.task.json`);
164
- try{
163
+
165
164
  fs.rename(oldPath, newPath, (err) => {
166
165
  //if (err) throw err;
167
166
  callback(newPath);
168
167
  });
169
- }catch(e){
170
- callback(newPath);
171
- }
172
168
  },
173
169
  saveTaskResult:(subid, hasError, data)=>{
174
170
  let {taskFolderResult, taskFolderResultFailed} = main_config;