简体   繁体   English

使用Node.js和Kue,是否可以指定我希望任务执行的日期?

[英]Using Node.js and Kue, is there a way to specify a date I want a task to execute?

Obviously I can set the delay to the number of miliseconds until the date I want, but that's not really going to work well in some cases, max int values are going to be a problem. 显然,我可以将延迟设置为直到我想要的日期为止的毫秒数,但这在某些情况下效果不佳,最大int值将是一个问题。 If Kue can't do it, I can store date-specific jobs that are too far away in the main database that the client facing app uses, or maybe a third store, I'm just trying to avoid using more than one store for this process. 如果Kue无法做到,我可以将特定日期的作业存储在面向客户端的应用程序使用的主数据库中,或者将其存储在第三数据库中,而这可能只是为了避免使用多个存储库。这个过程。

UPDATE: This is a silly question, I did some math in my head quickly and failed horribly, I guess, then asked, I should have calculated exactly before I asked. 更新:这是一个愚蠢的问题,我很快脑子里做了一些数学运算,却以失败告终,我想然后问,我应该在问之前已经计算了。

Kue doesn't have any other way to scheduling a job, unfortunately. 不幸的是,Kue没有其他安排工作的方式。 I do wonder what jobs you have that are need to be scheduled so far out as to overflow an integer. 我确实想知道您需要安排哪些工作,以至于溢出整数。 Considering Kue is backed by Redis I probably wouldn't want to rely on it to schedule jobs many years into the future. 考虑到Kue得到Redis的支持,我可能不想依靠它来安排未来很多年的工作。

If you really have to do it, then you could store the execute date with the job, and have the delay set as high as possible. 如果确实需要这样做,则可以将执行日期与作业一起存储,并将延迟设置得尽可能高。 When it comes time to execute, check if that date has passed, and if not then just requeue the job with the remaining ms, or with the max if the remaining is still too high. 当执行时间到时,请检查该日期是否已过,如果没有过,则仅用剩余的ms重新排定作业,如果剩余的仍然太高则重新排定最大值。

I wouldn't worry about it due to the size of the max integer in JavaScript . 由于JavaScript中max整数的大小,我不必担心。

The documentation states that the dates are relative to now , so you can schedule jobs to start up to 285,427.017 years (9,007,199,254,740,992 milliseconds) into the future. 该文档指出,日期是相对于现在的日期 ,因此您可以安排作业开始到未来的285,427.017年(9,007,199,254,740,992毫秒)。 Even though it says that it most likely converts the date to an absolute date which has a smaller but still rather large limit of just under: 243,090.534 years 97,671,189,983,570,992 milliseconds). 即使它说它很可能将日期转换为绝对日期,该绝对日期的下限值较小但仍然很大:243,090.534年97,671,189,983,570,992毫秒)。

Time wise I'd be more considered about the 32-bit second overflow in 2038. 在时间上,我会更考虑2038年的32位第二次溢出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM