我需要在函数超时之前退出循环,为此,在AWS Lambda中,我们通常使用get_remaining_time_in_millis来实现此目的。

do {
... // process the tasks in small batches that can be completed in, say, less than 10s
// when there's less than 10s left, stop
} while (context.getRemainingTimeInMillis() > 10000);


是否有类似的方法可以在GCP中完成相同任务?我试图避免通过rest api调用来获取函数配置并自己实现。

最佳答案

在这里放火

我认为Google Cloud Functions目前无法提供这样的价值。如果您确实需要类似的内容,则必须自己记录代码首次启动的时间,并根据您配置的最大运行时间对其进行跟踪,这可以通过阅读FUNCTION_TIMEOUT_SEC环境变量来获取。

虽然这听起来像是一个合理的功能,所以我建议filing a feature request

07-26 03:58