Browse Source

监听任务进度

哆啦好梦 2 years ago
parent
commit
70a1355c4a
2 changed files with 22 additions and 5 deletions
  1. 9 0
      electron/config/config.default.js
  2. 13 5
      electron/controller/example.js

+ 9 - 0
electron/config/config.default.js

@@ -138,6 +138,15 @@ module.exports = (appInfo) => {
   };
 
   /**
+   * 异常捕获
+   */
+  config.exception = {
+    mainExit: false,
+    childExit: true,
+    rendererExit: true,
+  };  
+
+  /**
    * 插件功能
    */
   config.addons = {

+ 13 - 5
electron/controller/example.js

@@ -686,16 +686,24 @@ class ExampleController extends Controller {
     let jobId = args.id;
     if (args.type == 'timer') {
       let myjob = new ChildJob();
-      myjob.exec('./jobs/example/timer', {jobId});
-  
+      let timerTask = myjob.exec('./jobs/example/timer', {jobId});
+
       // 监听任务进度
       const channel = 'controller.example.timerJobProgress';
-      myjob.on('job-timer-progress', (data) => {
-        Log.info('[main-process] from TimerJob data:', data);
+
+      timerTask.emitter.on('job-timer-progress', (data) => {
+        Log.info('[main-process] timerTask, from TimerJob data:', data);
 
         // 发送数据到渲染进程
         event.reply(`${channel}`, data)
       })
+      
+      // myjob.on('job-timer-progress', (data) => {
+      //   Log.info('[main-process] myjob, from TimerJob data:', data);
+
+      //   // 发送数据到渲染进程
+      //   event.reply(`${channel}`, data)
+      // })
     }
     
     return;
@@ -706,7 +714,7 @@ class ExampleController extends Controller {
    */ 
   createJobPool (args, event) {
 
-    
+
     
     return;
   }