【问题标题】:What alternative for get_remaining_time_in_millis in AWS Lambda is available for Google Cloud Function?AWS Lambda 中的 get_remaining_time_in_millis 有什么替代方法可用于 Google Cloud Function?
【发布时间】:2019-08-05 06:31:36
【问题描述】:

我需要在函数超时之前退出循环,为此在 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 来获取函数配置并自己实现它。

【问题讨论】:

    标签: python aws-lambda google-cloud-functions serverless


    【解决方案1】:

    firebaser 在这里

    我认为 Google Cloud Functions 目前还没有体现出这样的价值。如果你真的需要这样的东西,你必须自己实现它,记录你的代码第一次启动的时间,并根据你配置的最大运行时间跟踪它,你可以通过阅读 FUNCTION_TIMEOUT_SEC 环境变量来获得。

    这听起来像是一个合理的功能,所以我推荐filing a feature request

    【讨论】:

    • documentation 表示您可以使用环境变量 FUNCTION_TIMEOUT_SEC 获取当前函数的超时时间。但正如你所说,如果你想避免超时,你将不得不自己计算剩余时间。
    • 感谢道格的更新。这确实意味着基本的构建块就在那里,你只需要把它们放在一起。
    猜你喜欢
    • 2020-11-12
    • 2023-02-26
    • 2023-04-01
    • 2017-03-10
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 2017-12-17
    相关资源
    最近更新 更多