Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg-schedule: 超过一定范围无效 #709

Closed
strawberry224 opened this issue Apr 1, 2017 · 8 comments
Closed

egg-schedule: 超过一定范围无效 #709

strawberry224 opened this issue Apr 1, 2017 · 8 comments

Comments

@strawberry224
Copy link

  • Node Version: 7.7.4
  • Egg Version: 1.0
  • Plugin Name: egg-schedule
  • Plugin Version: 2.3.0
  • Platform: ubuntu 14

egg-schedule通过setTimeout来控制程序运行的间隔时间,但是其参数有限制不能超过int的范围,因此当我执行如每月执行一次的定时任务时就不会按照预期运行。

@atian25
Copy link
Member

atian25 commented Apr 1, 2017

你不是用egg-schedule 的 cron 方式?

@dead-horse
Copy link
Member

@strawberry224 这类的定时任务确定不是你设计有问题?你的服务会超过一个月都不重启么?�用 cron 类型的 schedule 吧

@atian25
Copy link
Member

atian25 commented Apr 1, 2017

好像是有问题,cron 也是转 setTimeout
@dead-horse

@dead-horse
Copy link
Member

dead-horse commented Apr 1, 2017

一年的毫秒数:365 * 24 * 60 * 60 * 1000 = 31536000000,你需要一个多长的定时任务会放不下?

@dead-horse
Copy link
Member

https://github.com/nodejs/node/blob/master/lib/timers.js#L32 node 有做这个限制,大概是 24 天,egg-schedule 不支持设置超过这个长度的定时任务,我会去加 egg-schedule 加一下报错提示

@atian25
Copy link
Member

atian25 commented Apr 1, 2017

应该是不支持两次间隔超过 24 天,只能设置小一点。自己判断了

@strawberry224
Copy link
Author

strawberry224 commented Apr 1, 2017

@atian25 谢谢大家的解答,由于业务量不大,我本想一个月清除一次临时图片文件,这个设计确实存在问题。如果不支持的话,我改小一点时间也是OK的 :)
不过其实非要实现应该也是可以的,比如循环执行setTimeout这种馊主意……:

function wait(nextTick, max) {
  return new Promise((resolve, reject) => {
    if (nextTick < max) {
      return resolve(nextTick);
    }

    setTimeout(() => {
      wait(nextTick - max, max);
    }, max);
  })
}
const TIMEOUT_MAX = 2147483647;
wait(nextTick - now, TIMEOUT_MAX).then(result => {
  setTimeout(() => {
    ... ...
  }, result);
});

@atian25
Copy link
Member

atian25 commented Sep 29, 2017

@strawberry224 忘记说了,在 eggjs/schedule#19 已经解决这个问题了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants