App Engine Cron.yaml run multiple instances of a script

时间:2015-07-31 19:27:24

标签: google-app-engine cron

How can one run multiple instances of a Script Using Google App Engine's Cron system?

By default, it will run, then wait the specified interval before running again, which means that only one instance runs. What i am looking for is how one can get a script that takes 2+ minutes to run start a new instance every 30-60 seconds regardless of if it is running already or not, which does assume the script does not interfere with itself if multiple instances are running. this would effectively allow the script to deal with several times more information in the same period of time.

Edit, Completely reworded the question.

3 个答案:

答案 0 :(得分:1)

你只能获得分钟的分辨率。为了获得更细粒度,你需要知道他们是否应该立即处理来自chron的请求的实例,如果他们必须先睡30秒。 30秒的睡眠时间占用60秒请求截止日期的一半。根据您希望处理的工作负载,这可能需要您使用模块。

顺便说一下,我不知道保证计划在01:00的作业会在正好 01:00:00(而不是在01:00: 03)。

答案 1 :(得分:1)

由于cron服务不允许小于1分钟的间隔,因此您需要以不同的方式实现错误的脚本启动。 一种可能性是让cron条目处理程序每​​2分钟运行一次,在内部休眠30秒(或者与你的“其他”要求的“几秒”一样低)触发相应的脚本实例启动之间。

注意:睡眠可能会燃烧到您的实例小时使用情况。您可能能够将交错的触发逻辑合并到您可能拥有的其他长期任务中,而不是简单地睡觉。

要将实际脚本执行与cron处理程序(或其他长期任务)执行分离,您可以为每个脚本实例使用专用任务队列,如果需要,队列处理程序可以共享实际的脚本代码。实际的触发将通过在相应的脚本实例队列中排队任务来完成。作为奖励,您可以通过自定义相应的队列配置来进一步控制每个脚本实例的执行。

注意:如果您的脚本执行时间超过了2分钟的cron周期,您可能需要在队列配置中采取额外的预防措施,因为可能会有额外的延迟(由于排队),这可能会推动相应的脚本实例更接近下一个实例启动。

答案 2 :(得分:0)

解决Dave W. Smith的回答,The Line将是

every 1 minute from 00:00 to 23:59

这意味着它会每分钟创建一个新实例,即使脚本运行时间超过一分钟。似乎无法指定秒数。

相关问题