简体   繁体   English

如何在Firebase Cloud Functions上拆分长时间执行的功能

[英]How to split long execution time functions on Firebase Cloud Functions

Let's say I have function A, B, C, D, all of them are not exceed the execution time limit of Firebase Cloud Functions. 假设我有函数A,B,C,D,它们都没有超过Firebase Cloud Functions的执行时间限制。 But if at the end of function A it calls function B, at the end of function B, it calls function C ... and so on, like below: 但是,如果在函数A的末尾调用函数B,在函数B的末尾调用函数C ...依此类推,如下所示:

function A(): Promise {
    doStuffA()
    return httpPostFunctionB()
}

function B(): Promise {
    doStuffB()
    return httpPostFunctionC()
}

function C(): Promise {
    doStuffC()
    return httpPostFunctionD()
}

function D() {
    doStuffD()
}

All together it will exceed the time limit. 总计将超过时间限制。

Is there any way to make function A no need to wait for function B, but also guarantee function B will be executed completely? 有什么方法可以让功能A不必等待功能B,又可以保证功能B可以完全执行?

I think it is possible, we can just make function A modify some value in Firestore, and make function B listen to that value change. 我认为有可能,我们可以使功能A在Firestore中修改一些值,并使功能B侦听该值更改。 But I wonder if there is a cleaner way to do this. 但我想知道是否有更清洁的方法来做到这一点。

You can extend the timeout for Cloud Functions. 您可以延长Cloud Functions的超时时间。 The default of 1 minute can be extended up to 9 minutes. 默认的1分钟可以延长到9分钟。 Please read the documentation about that. 阅读有关此文档

If you need more than 9 minutes, you'll need to consider delegating the work to a service that doesn't have strict restrictions, such as App Engine or Compute Engine. 如果您需要9分钟以上的时间,则需要考虑将工作委派给没有严格限制的服务,例如App Engine或Compute Engine。 But the 9 minute limit for Cloud Functions can't be changed. 但是无法更改9分钟的云功能限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM