mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 03:52:07 +08:00
job
This commit is contained in:
@@ -680,16 +680,23 @@ class ExampleController extends Controller {
|
||||
/**
|
||||
* 任务
|
||||
*/
|
||||
someJob (args) {
|
||||
someJob (args, event) {
|
||||
let jobId = args.id;
|
||||
if (args.type == 'timer') {
|
||||
let myjob = new ChildJob();
|
||||
myjob.exec('./jobs/example/timer', {jobId});
|
||||
|
||||
myjob.on('job-timer', (data) => {
|
||||
Log.info('from TimerJob data:', data);
|
||||
// 监听任务进度
|
||||
const channel = 'controller.example.timerJobProgress';
|
||||
myjob.on('job-timer-progress', (data) => {
|
||||
Log.info('[main-process] from TimerJob data:', data);
|
||||
|
||||
// 发送数据到渲染进程
|
||||
event.reply(`${channel}`, data)
|
||||
})
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,14 +24,13 @@ class TimerJob extends Job {
|
||||
|
||||
// 模拟计时器任务,执行10秒
|
||||
let childMessage = Message.childMessage;
|
||||
let eventName = 'job-timer';
|
||||
let eventName = 'job-timer-progress';
|
||||
let number = 0;
|
||||
let jobId = this.params.jobId;
|
||||
setInterval(function() {
|
||||
Log.info("[child-process] TimerJob number: ", number);
|
||||
Hello.welcome();
|
||||
|
||||
childMessage.sendToMain(eventName, {number, jobId});
|
||||
childMessage.sendToMain(eventName, {jobId, number});
|
||||
number++;
|
||||
}, 1000);
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
** preload为预加载模块,该文件将会在程序启动时加载 **
|
||||
*************************************************/
|
||||
|
||||
const ChildJob = require('ee-core/module/jobs/child');
|
||||
|
||||
/**
|
||||
* 预加载模块入口
|
||||
* @param {Object} app - 全局app对象
|
||||
@@ -20,7 +18,4 @@ module.exports = async (app) => {
|
||||
securityAddon.create();
|
||||
awakenAddon.create();
|
||||
autoUpdaterAddon.create();
|
||||
|
||||
// let myjob = new ChildJob();
|
||||
// myjob.exec('./jobs/example/index');
|
||||
}
|
||||
@@ -35,6 +35,7 @@ const ipcApiRoute = {
|
||||
startJavaServer: 'controller.example.startJavaServer',
|
||||
closeJavaServer: 'controller.example.closeJavaServer',
|
||||
someJob: 'controller.example.someJob',
|
||||
timerJobProgress: 'controller.example.timerJobProgress',
|
||||
hello: 'controller.example.hello',
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ export const constantRouterMap = [
|
||||
name: 'BaseWindowIndex',
|
||||
component: () => import('@/views/base/window/Index')
|
||||
},
|
||||
{
|
||||
path: '/base/jobs/index',
|
||||
name: 'BaseJobsIndex',
|
||||
component: () => import('@/views/base/jobs/Index')
|
||||
},
|
||||
{
|
||||
path: '/base/notification/index',
|
||||
name: 'BaseNotificationIndex',
|
||||
|
||||
@@ -39,6 +39,12 @@ export default {
|
||||
pageName: 'BaseSqliteDBIndex',
|
||||
params: {}
|
||||
},
|
||||
'menu_330' : {
|
||||
icon: 'profile',
|
||||
title: '任务',
|
||||
pageName: 'BaseJobsIndex',
|
||||
params: {}
|
||||
},
|
||||
'menu_400' : {
|
||||
icon: 'profile',
|
||||
title: '视图',
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
<div id="app-base-jobs">
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
1. 任务
|
||||
1. 任务/并发任务
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-space>
|
||||
<a-button @click="runJob(1)">执行任务1</a-button>
|
||||
进度:{{ message1 }}
|
||||
进度:{{ progress1 }}
|
||||
</a-space>
|
||||
<p></p>
|
||||
<a-space>
|
||||
<a-button @click="runJob(2)">执行任务2</a-button>
|
||||
进度:{{ message2 }}
|
||||
进度:{{ progress2 }}
|
||||
</a-space>
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,14 +33,19 @@ export default {
|
||||
methods: {
|
||||
init () {
|
||||
// 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次
|
||||
this.$ipc.removeAllListeners(ipcApiRoute.someJob);
|
||||
this.$ipc.on(ipcApiRoute.someJob, (event, result) => {
|
||||
this.$ipc.removeAllListeners(ipcApiRoute.timerJobProgress);
|
||||
|
||||
// 监听任务进度
|
||||
this.$ipc.on(ipcApiRoute.timerJobProgress, (event, result) => {
|
||||
console.log('[ipcRenderer] [someJob] result:', result);
|
||||
switch (result.jId) {
|
||||
|
||||
switch (result.jobId) {
|
||||
case 1:
|
||||
this.progress1 = result.progress1;
|
||||
this.progress1 = result.number;
|
||||
break;
|
||||
case 2:
|
||||
this.progress2 = result.progress2;
|
||||
this.progress2 = result.number;
|
||||
break;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user