thinkjs / thinkjs

Use full ES2015+ features to develop Node.js applications, Support TypeScript.
https://thinkjs.org/
MIT License
5.31k stars 617 forks source link

定时器中,设置type=one ,依然所有子进程都执行任务? #1491

Closed firendlys closed 4 years ago

firendlys commented 4 years ago

DESC

设置 worker>1 , 然后设置一个定时器,type=one , 运行时发现所有 worker 子进程都调用了 handle函数. 删掉 type 字段也一样. 按照文档所写,设置 type=one (或者省略 type ),均只在第一个子进程中执行.

ENV

OS Platform: win10 Node.js Version: v14.2.0 ThinkJS Version: 3.2.11

code

// config/crontab.js
module.exports = [{
    interval: '30s',
    immediate: true,
    handle: function(){
        think.logger.info("onTimer");
    },
    type: "one",
}]

error message

npm start
> proj1@1.0.0 start I:\test-thinkjs\proj1
> node development.js

[2020-06-03T18:14:35.935] [15752] [INFO] - Server running at http://127.0.0.1:8360
[2020-06-03T18:14:35.940] [15752] [INFO] - ThinkJS version: 3.2.11
[2020-06-03T18:14:35.941] [15752] [INFO] - Environment: development
[2020-06-03T18:14:35.950] [15752] [INFO] - Workers: 3
[2020-06-03T18:14:39.943] [12888] [INFO] - onTimer
  think-crontab run task interval: 30s, pid:12888 +0ms
[2020-06-03T18:14:40.005] [15064] [INFO] - onTimer
  think-crontab run task interval: 30s, pid:15064 +0ms
[2020-06-03T18:14:40.100] [15216] [INFO] - onTimer
  think-crontab run task interval: 30s, pid:15216 +0ms
  think-crontab run task interval: 30s, pid:12888 +30s
[2020-06-03T18:15:09.921] [12888] [INFO] - onTimer
  think-crontab run task interval: 30s, pid:15064 +30s
[2020-06-03T18:15:09.992] [15064] [INFO] - onTimer
  think-crontab run task interval: 30s, pid:15216 +30s
[2020-06-03T18:15:10.081] [15216] [INFO] - onTimer
终止批处理操作吗(Y/N)? 
^C
lizheming commented 4 years ago

验了下好像是 Windows 上专有的问题,我们看看。

lizheming commented 4 years ago

think-cluster@1.5.7 修复了这个问题,你重装下依赖再试试吧。

licumt217 commented 4 years ago

think-cluster@1.5.7 修复了这个问题,你重装下依赖再试试吧。

我这边mac,相同的问题,think-cluster更新到1.5.7了,依旧这个问题