Firebase cloud function always timeout

后端 未结 2 1196
太阳男子
太阳男子 2020-12-29 09:21

I\'m exploring the firebase cloud functions and I\'m trying to send a notifications with an http request.

The problem is that even if I manage to send the notificati

相关标签:
2条回答
  • 2020-12-29 09:57

    HTTP-triggered Cloud Functions work just like Express apps -- you have a response object (res) that you need to use to send something when the request is done. In this case, it looks like you could do something like:

    return Promise.all([
      /* ... */
    ]).then(() => {
      res.status(200).send('ok');
    }).catch(err => {
      console.log(err.stack);
      res.status(500).send('error');
    });
    
    0 讨论(0)
  • 2020-12-29 10:14

    @Michael Bleigh answer is perfectly fine for this question, let me add more in this for the future users.

    As per firebase documentation:-

    Use these recommended approaches to manage the lifecycle of your functions:

    • Resolve functions that perform asynchronous processing (also known as "background functions") by returning a JavaScript promise.

    • Terminate HTTP functions with res.redirect(), res.send(), or res.end(). (The case in this question.)

    • Terminate a synchronous function with a return; statement.

    Note It's important to manage the lifecycle of a function to ensure that it resolves properly. By terminating functions correctly, you can avoid excessive charges from functions that run for too long or loop infinitely. Also, you can make sure that the Cloud Functions instance running your function does not shut down before your function successfully reaches its terminating condition or state.

    • You need a paid plan (Blaze, pay as you go) to access external APIs.

    You might see below warning in firebase functions log if the billing account is not configured.

    Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions

    Check this link for more information.

    0 讨论(0)
提交回复
热议问题