我是firebase和异步javascript的新手。我正试图在firebase中创建一个计划任务,从一个集合中获取一堆rss URL,对其进行解析并将其存储在另一个集合内,但我在执行时收到错误:4 DEADLINE_EXCEEDED:Object.callErrorFromStatus处超过了最后期限。
const refreshRSS = functions.pubsub.schedule('every 30 mins').onRun(async context => {
let newRSS = addRSS();
return await newPodcasts;
});
addRSS = async () => {
const newRSSFeed = new Array();
let rssURLs = await db.collection('rssURLs').get();
rssURLs.forEach(async rssURLsObject=>{
rss = rssURLsObject.data();
let rssData = await parser.parseURL(rss.url);
newRSSFeed.push(db.collection('rss').doc(encodeURIComponent(rss.url))
.set(podcast));
})
return newRSSFeeds;
}
我还尝试在refreshRSS中返回Promise.all(newRSS(,但它抛出了另一个错误:不可迭代。我不确定到底什么是firebase期望的返回参数。
当您必须在循环中解析promise时,请尝试使用map。这将起作用:
const refreshRSS = functions.pubsub.schedule('every 30 mins').onRun(async context => {
let newRSS = await addRSS();
return await newPodcasts;
});
addRSS = async () => {
const newRSSFeed = new Array();
let rssURLs = await db.collection('rssURLs').get();
let promise = rssURLs.map(async rssURLsObject=>{
rss = rssURLsObject.data();
let rssData = await parser.parseURL(rss.url);
let con = await db.collection('rss').doc(encodeURIComponent(rss.url)
newRSSFeed.push(con)
.set(podcast));
})
await Promise.all(promise)
return newRSSFeeds;
}