在AppEngine定时任务中如何处理每天、每周、每月、每年 (python)
我正在尝试设置一个应用引擎的任务,让它每天、每周、每月和每年在午夜重复执行,目的是清空一个游戏的高分榜。
我的cron.yaml文件看起来是这样的:
- description: daily clear
url: /delete?off=10
schedule: every day 00:00
- description: weekly clear
url: /delete?off=20
schedule: every monday 00:00
- description: monthly clear
url: /delete?off=30
schedule: every month 00:00
- description: yearly clear
url: /delete?off=40
schedule: every year 00:00
每天和每周的任务都设置得不错,但我就是搞不懂怎么让一个任务每月和每年重复执行。这是调度格式。
对于每月的任务,我试过像“每月一次”、“每月的第一天”等表达方式,但都没有成功。请问这种调度在cron任务中可以实现吗?
还是说我只需要每天在00:00调用清空页面,然后在页面中判断当前日期,看看是否是周/月/年的开始?
2 个回答
3
我会选择这样的方式:
- description: daily clear
url: /delete/daily
schedule: every day 00:00
- description: weekly clear
url: /delete/weekly
schedule: every monday 00:00
- description: monthly clear
url: /delete/monthly
schedule: first of month 00:00
- description: yearly clear
url: /delete/yearly
schedule: first of jan 00:00
据我所知,你不能在 yaml
中使用像 /delete?off=30
这样的语法。你需要为每种不同的清除操作明确地定义一个路由,比如 /delete/weekly
。
36
你提供的文档里有一些例子,展示了你可以如何实现你想要的所有结果。
# Daily:
every day 00:00
# Weekly:
every monday 00:00
# Monthly:
1 of month 00:00
# Yearly:
1 of jan 00:00