[v1.3] Cron 相关修改:bug 修补、i18n、once 表达式增强、升级 cron 库 #1126
+530
−157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概述 Descriptions
增强 once 表达式处理
现时只有 once -> * 做法
假如开发者只想在某几天运行一次, 现在做不到
因此引入以下写法
@cronjob * 19-22 once(11,21,31) * *在11日,21日,31日,一天只执行一次。
@cronjob * 21 once(6-17) * *在6-17日,晚上9时,一天只执行一次。
once(*)crontabExec 引入 timeDiff 修正执行时间判断
flag = last.getHours() !== now.getHours();这种写法存在问题你假设了连续运行
假如脚本在 星期一 8:23分执行了
然后8:25分关掉电脑
再在 星期二 8:17分打开电脑
这样
last.getHours() !== now.getHours()就会判断为 false, 导致错误地没有执行升级 cron 至 4.4.0
注
cron 内部有 luxon. 如有需要,可以在 package.json 加 luxon,使代码好看一点
可改成