简体   繁体   English

使用App Engine的cron API每小时运行一个任务

[英]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: 或者:

  1. Have a single task queue entry that, when it runs, enqueues a new task with the 'countdown' set to the number of seconds until the next time you want to run. 有一个任务队列条目,当它运行时,将一个新的任务排队,并将'倒计时'设置为下次要运行的秒数。
  2. Have a daily cron job that enqueues 24 hourly taskqueue entries at each of the times you want it to run. 每天都有一个cron作业,它可以在每个要运行的时间内排入24小时的任务队列条目。

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.

相关问题 如何制作一个 cron.yaml 文件以每小时运行一次 python 脚本,用于谷歌云应用引擎 - How can I make a cron.yaml file to run python script every hour for google cloud app engine Python - 计划:每小时运行 function + “整点” - Python - Schedule: Run function every hour + "on the hour" 运行celery定期任务1小时,然后花费1小时以上,该任务到期? - Run celery periodic task for 1 hour, it it takes more then 1 hour, expire that task? 如何创建一个任务计划程序,使它每天每天运行我的.py文件? - How to create a task scheduler which one run my .py file in every hour in every day? 在特定的一天每小时运行一个脚本 - Run a script every hour on a specific day 安排 Python 脚本每小时准确运行 - Scheduling Python Script to run every hour accurately 如何让我的函数每小时运行一次? - How to make my function run every hour? 如何安排一个函数在 Flask 上每小时运行一次? - How to schedule a function to run every hour on Flask? 安排一个 python 脚本每小时运行一次 - schedule a python script to run every hour 运行 Django API,执行时间为 1 小时 - Run Django API that has 1 hour to execution time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM