From b99de9fcf06a2ef349c6627b5899be147cdd215b Mon Sep 17 00:00:00 2001 From: gaoshuaixing Date: Tue, 11 Mar 2025 15:20:23 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E4=BC=98=E5=8C=96=20job=20=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=80=92=E8=AE=A1=E6=97=B6?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/jobs/example/timer.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/electron/jobs/example/timer.js b/electron/jobs/example/timer.js index ed70364..551b8b0 100644 --- a/electron/jobs/example/timer.js +++ b/electron/jobs/example/timer.js @@ -12,8 +12,7 @@ const { UserService } = require('../../service/job/user'); */ class TimerJob { - constructor(params) { - this.params = params; + constructor() { this.timer = undefined; this.timeoutTimer = undefined; this.number = 0; @@ -22,10 +21,11 @@ class TimerJob { /** * handle()方法是必要的,且会被自动调用 + * params 传递的参数 */ - async handle () { - logger.info("[child-process] TimerJob params: ", this.params); - const { jobId } = this.params; + async handle(params) { + logger.info("[child-process] TimerJob params: ", params); + const { jobId } = params; // 子进程中使用service // 1. 确保引入的 service 中不能有electron 的 api或依赖, electron 不支持 @@ -33,6 +33,9 @@ class TimerJob { userService.hello('job'); // 执行任务 + // 多次运行时,重置倒计时 + this.number = 0; + this.countdown = 10; this.doTimer(jobId); }