如何为连续的数据流提供连续的 Firebase 云功能? [英] How can I have a continuous firebase cloud function for a continuous stream of data?
问题描述
我需要使用 Twitter Stream API 将推文数据流式传输到我的 Firebase 云函数,如下所示:
I need to use the Twitter Stream API to stream tweet data to my firebase cloud function like this:
client.stream('statuses/filter', params, stream => {
stream.on('data', tweet => {
console.log(tweet);
})
stream.on('error', error => {
console.log(error)
})
})
流是连续的,但 Firebase 云功能在一段时间后关闭.我可以使用什么解决方案来持续接收流数据?
The stream is continuous but the firebase cloud function shuts down after a certain period of time. What solution could I make use of to be able to continuously receive the stream data?
推荐答案
Cloud Functions 的最长运行时间为 540 秒 如文档所述.您可能不得不考虑使用 Google Cloud 中的计算引擎实例,您可以在其中运行代码没有限制.或者您可以考虑使用 Google Cloud Scheduler 每隔 x 次运行您的函数以获取新推文.
Cloud Functions have a max running time of 540 seconds as documented. You would have to look at probably using a Compute Engine Instance from Google Cloud where you can have code running without limits. Or you could look at using the Google Cloud Scheduler to run your function every x time to get new tweets.
这篇关于如何为连续的数据流提供连续的 Firebase 云功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!