Cron表达式用于调度作业。

huangapple go评论56阅读模式
英文:

Cron Expression to schedule a job

问题

我想在特定的时间表上运行我的代码。因此,我需要一个Cron表达式来安排每个月的第12天的工作,但不包括星期六和星期日(即仅在工作日安排工作的第12天)。是否可以安排这样的任务?可以有人帮助找到解决方案吗?

英文:

I would like to run my code on specific schedule.So i need a cron expression to schedule a job for every 12th day of the month by excluding saturdays and sundays (means scheduling a job only on weekdays for every 12th day of the month). Is this possible to schedule ??

Can someone help for the solution to get me out here

答案1

得分: 1

是的,这是很容易实现的。

5 4 */12 * 1-5

"如果每个月的第12天是星期一到星期五,那么在每天的04:05执行任务。"

编辑:我误解了问题,抱歉。我认为只使用CRON字符串本身不可能实现这一点。

作为一个简单的解决方案建议:只需将任务安排在每个工作日执行(例如5 4 * * 1-5),然后在作业开始时检查是否是每个月的第12个工作日工作日。如果是,启动您的业务流程,如果不是,就退出。

英文:

Yes it's easily possible.

5 4 */12 * 1-5

> “At 04:05 on every 12th day-of-month if it's on every day-of-week from Monday through Friday.”

Edit: I misunderstood the question, sorry. I don't think that's possible only with the CRON string itself.

As an easy solution proposal: just schedule the task itself every business day (e.g. 5 4 * * 1-5) and then check at the start of the job if it is the 12th business day of the month. If so, start your business process and if not just exit.

huangapple
  • 本文由 发表于 2020年7月28日 14:07:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63128003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定