哆啦好梦 2 tahun lalu
induk
melakukan
85e6ac5f57

+ 12 - 10
electron/controller/example.js

@@ -689,13 +689,7 @@ class ExampleController extends Controller {
     switch (action) {
       case 'create':
         result = this.service.example.doJob(jobId, action, event);
-        break;
-      case 'pause':
-        this.service.example.doJob(jobId, action, event);
-        break;
-      case 'continue':
-        this.service.example.doJob(jobId, action, event);
-        break;        
+        break;       
       case 'close':
         this.service.example.doJob(jobId, action, event);
         break;
@@ -728,12 +722,20 @@ class ExampleController extends Controller {
    */ 
   someJobByPool (args, event) {
     let jobId = args.id;
-    let type = args.type;
-    let pid = this.service.example.doJobByPool(jobId, type, event);
+    let action = args.action;
+    
+    let result;
+    switch (action) {
+      case 'run':
+        result = this.service.example.doJobByPool(jobId, action, event);
+        break;
+      default:  
+    }
     
     let data = {
       jobId,
-      pid
+      action,
+      result
     }
     return data;
   }

+ 12 - 10
electron/service/example.js

@@ -63,7 +63,7 @@ class ExampleService extends Service {
     if (action == 'close') {
       oneTask = this.taskForJob[jobId];
       oneTask.kill();
-      event.reply(`${channel}`, {jobId, number:0, pid:0});
+      event.sender.send(`${channel}`, {jobId, number:0, pid:0});
     }    
 
     return res;
@@ -74,8 +74,6 @@ class ExampleService extends Service {
    */ 
   doCreatePool(num, event) {
     const channel = 'controller.example.createPoolNotice';
-
-    // let pids = await myjobPool.create(num);
     this.myJobPool.create(num).then(pids => {
       event.reply(`${channel}`, pids);
     });    
@@ -84,22 +82,26 @@ class ExampleService extends Service {
   /**
    * 通过进程池执行任务
    */ 
-  doJobByPool(jobId, type, event) {
-    let pid = 0;
-    if (type == 'timer') {
+  doJobByPool(jobId, action, event) {
+    let res = {};
+    let timerTask;
+    const channel = 'controller.example.timerJobProgress';
+    if (action == 'create') {
 
       // 执行任务及监听进度
-      const channel = 'controller.example.timerJobProgress';
-      const timerTask = this.myJobPool.run('./jobs/example/timer', {jobId});
+      timerTask = this.myJobPool.run('./jobs/example/timer', {jobId});
       timerTask.emitter.on('job-timer-progress', (data) => {
         Log.info('[main-process] [ChildPoolJob] timerTask, from TimerJob data:', data);
 
         // 发送数据到渲染进程
         event.sender.send(`${channel}`, data)
       })
-      pid = timerTask.pid; 
+      res.pid = timerTask.pid; 
+
+      // ???
+      //this.taskForJobPool[jobId] = timerTask;
     }
-    return pid;
+    return res;
   }
 
   /**

+ 0 - 1
frontend/src/api/main.js

@@ -39,7 +39,6 @@ const ipcApiRoute = {
   createPool: 'controller.example.createPool',
   createPoolNotice: 'controller.example.createPoolNotice',
   someJobByPool: 'controller.example.someJobByPool',
-  timerJobProgressByPool: 'controller.example.timerJobProgressByPool',
   hello: 'controller.example.hello',
 }
 

+ 8 - 3
frontend/src/views/base/jobs/Index.vue

@@ -30,13 +30,13 @@
       </a-space>
       <p></p>      
       <a-space>
-        <a-button @click="runJobByPool(3, 'create')">执行任务3</a-button>
+        <a-button @click="runJobByPool(3, 'run')">执行任务3</a-button>
         进度:{{ progress3 }} , 进程pid:{{ progress3_pid }}
         <a-button @click="runJob(3, 'close')">关闭</a-button>
       </a-space>
       <p></p>
       <a-space>
-        <a-button @click="runJobByPool(4, 'create')">执行任务4</a-button>
+        <a-button @click="runJobByPool(4, 'run')">执行任务4</a-button>
         进度:{{ progress4 }} , 进程pid:{{ progress4_pid }}
         <a-button @click="runJob(4, 'close')">关闭</a-button>
       </a-space>            
@@ -133,9 +133,14 @@ export default {
         switch (data.jobId) {
           case 3:
             this.progress3_pid = data.pid;
+            if (data.action == 'run') {
+              this.progress1_pid = data.result.pid;
+            }
             break;
           case 4:
-            this.progress4_pid = data.pid;
+            if (data.action == 'run') {
+              this.progress4_pid = data.result.pid;
+            }
             break;
         }
       })