Cron表达式以在每月的第一个星期二运行,星期二后面应该是一个星期一。

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

Cron expression to run on first Tuesday of the month, Tuesday should be followed by a Monday

问题

我想安排一个 Lambda 函数,在每个月的第一个星期二运行。但是星期二应该紧跟在星期一后面。
例如:
8月1日:星期二 -> 不应调用 Lambda
8月7日:星期一,8月8日:星期二 -> 应调用 Lambda
我无法找到相应的 cron 表达式。
任何提示都会有帮助!

英文:

I want to schedule a lambda function to run on first Tuesday every month. But the Tuesday should be followed by Monday.
Ex:
Aug 1: Tuesday -> Lambda shouldn't get invoked
Aug 7: Monday, Aug 8: Tuesday -> Lambda should be invoked
I am not able to figure out the cron expression for the same.
Any leads would be helpful!

答案1

得分: 1

为简化问题,您可以说您需要在每个月的第一个星期一之后执行 Lambda 函数。
一种选项是在每月的第一个星期一的最后一分钟执行 Lambda。

cron(59 23 ? * 2#1 *)

此外,如果您使用 AWS 事件桥调度,还有灵活的时间窗口。

如果这对您不起作用,将需要创建一个 Lambda 来处理这个逻辑,因为 AWS cron 表达式不支持此逻辑。

英文:

To simplify your problem you can say that you need to execute the lambda the day after the first monday of the month, every month.
one option would be to execute the Lambda on the last minute of the first monday of the month.

cron(59 23 ? * 2#1 *)

Also if you use AWS event bridge schedules there is a flexible time windows.

If this doesn't work for you, it will be necessary to create a lambda to handle this logic, the AWS cron expression does not support this logic out of the box.

huangapple
  • 本文由 发表于 2023年6月9日 00:47:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434077.html
匿名

发表评论

匿名网友

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

确定