[英]Run a task every hour on the hour with App Engine's cron API
I need to run a task every hour on the hour (00:00, 01:00, 02:00, ..., 23:00) every day of the week, but can't seem to find an example in App Engine's docs of how to do this. 我需要在每周的每个小时(00:00,01:00,02:00,...,23:00)每小时运行一个任务,但似乎无法在App Engine中找到一个示例如何做到这一点的文档。
There is an example of running at ask every hour, but this doesn't fit because the "start" of that hour depends on when you deploy the application. 有一个每小时运行询问的示例,但这不合适,因为该小时的“开始”取决于您部署应用程序的时间。 That is, if I deploy at 4:37 PM, the cron scripts will get executed at 5:37, 6:37, ... instead of 5:00, 6:00, ...
也就是说,如果我在下午4:37部署,cron脚本将在5:37,6:37,...而不是5:00,6:00执行...
So far the only way that looks like it would work is to have 24 different cron entries, one for the specific hour of each day set to run each day at that specific time. 到目前为止,看起来它的唯一方法是有24个不同的cron条目,一个用于每天在特定时间运行的特定小时。
Does anyone know of anything that would let me use a schedule like "every hour at :00" or even "every day 00:00, 01:00, ... 23:00"? 有没有人知道任何让我使用“每小时在00:00”甚至“每天00:00,01:00,...... 23:00”的时间表?
You could do this, and give up the exactly on the hour, but it will be close... 你可以做到这一点,并准确地放弃一小时,但它会很接近......
(Example came from a app I was debuging) (示例来自我正在调试的应用程序)
cron:
- description: Description of what you want done...
url: /script/path/goes/here
schedule: every 60 minutes synchronized
timezone: America/New_York
Below is a screenshot of the logs, the app gets no traffic right now, 99% of those entries are all the cron entry. 下面是日志的截图,应用程序现在没有流量,其中99%的条目都是cron条目。
--- edit --- --- 编辑 ---
Just re-read the docs as well and maybe this might be better, 只需重新阅读文档,也许这可能会更好,
schedule: every 60 minutes from 00:00 to 23:59
Unfortunately, the cron syntax doesn't let you specify the time for intervals less than a day. 不幸的是,cron语法不允许您指定间隔小于一天的时间。 What you can do, however, is use the Task Queue for this.
但是,您可以使用任务队列进行此操作。 Either:
或者:
The docs say you can have 20 cron entries, so you can't have one for every hour of the day. 文档说你可以有20个cron条目,所以你不可能每天每小时都有一个。
You could run your task every minute and check if it is the first minute of the hour - exit otherwise. 您可以每分钟运行一次任务并检查它是否是一小时的第一分钟 - 否则退出。
Looking over the docs, I agree that your 24 cron entry idea is the only documented way that would work. 查看文档,我同意您的24个cron入口理念是唯一可行的文档化方法。 Not ideal, but should work.
不理想,但应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.