firebase云功能错误:连击:最大呼叫堆栈大小超过
我正在从API获取库存数据。
我希望每12:00 pm更新它。
但是,当我尝试部署此功能时
$ firebase部署 - 仅功能
出现错误。
错误:从来源加载函数定义无法从源:失败 从功能来源生成表现来源:连击:最大呼叫堆栈 大小超过
这是funtions/src中的“ index.ts”。
import * as functions from "firebase-functions";
import axios from "axios"
import { doc, getFirestore, setDoc, Timestamp } from 'firebase/firestore'
import { format } from 'date-fns'
import { initializeApp } from "firebase/app";
const firebaseConfig = {
apiKey: "***********",
authDomain: "****",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);
const API_KEY = "****************"
interface Wow {
clpr: string
srtnCd: string
}
const today = new Date();
const yesterday = today.setDate(today.getDate() - 1);
const basDt = format(yesterday, 'yyyyMMdd')
export const getStocks = functions
.region('asia-northeast3')
.pubsub.schedule('12 00 * * *')
.timeZone('Asia/Seoul').onRun(async (context) => {
await axios.get(`https://api.odcloud.kr/api/GetStockSecuritiesInfoService/v1/getStockPriceInfo?numOfRows=3000&resultType=json&basDt=${basDt}&serviceKey=${API_KEY}`)
.then(response => {
const wow: Wow[] = response.data.response.body.items.item
wow.map((v, index) => {
setDoc(doc(db, 'KRX', v.srtnCd), { day: Timestamp.fromDate(today), price: v.clpr })
})
return null;
})
})
另一个功能确实效果很好。 但是,如果我包括这个,那就不起作用。
我应该怎么办?
I'm tring to get stock data from an api.
and I want it be updated at every 12:00 PM.
but when I tring to deploy this funtions, using
$firebase deploy --only functions
the error comes out.
Error: Failed to load function definition from source: Failed to
generate manifest from function source: RangeError: Maximum call stack
size exceeded
This is "index.ts" in funtions/src.
import * as functions from "firebase-functions";
import axios from "axios"
import { doc, getFirestore, setDoc, Timestamp } from 'firebase/firestore'
import { format } from 'date-fns'
import { initializeApp } from "firebase/app";
const firebaseConfig = {
apiKey: "***********",
authDomain: "****",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);
const API_KEY = "****************"
interface Wow {
clpr: string
srtnCd: string
}
const today = new Date();
const yesterday = today.setDate(today.getDate() - 1);
const basDt = format(yesterday, 'yyyyMMdd')
export const getStocks = functions
.region('asia-northeast3')
.pubsub.schedule('12 00 * * *')
.timeZone('Asia/Seoul').onRun(async (context) => {
await axios.get(`https://api.odcloud.kr/api/GetStockSecuritiesInfoService/v1/getStockPriceInfo?numOfRows=3000&resultType=json&basDt=${basDt}&serviceKey=${API_KEY}`)
.then(response => {
const wow: Wow[] = response.data.response.body.items.item
wow.map((v, index) => {
setDoc(doc(db, 'KRX', v.srtnCd), { day: Timestamp.fromDate(today), price: v.clpr })
})
return null;
})
})
Another functions do work well .
but if I include this one, It doesn't work.
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为这是您的
functions \ src \ index.ts
文件,因此您只能从中导出云功能,而无需其他。因此,更改:
to:
如果要导出初始化的firebase SDK以供其他地方使用,请将其移至自己的文件,称为
functions \ src \ firebase.ts
(或类似):然后像这样使用:
Because this is your
functions\src\index.ts
file, you should only be exporting Cloud Functions from it and nothing else.So change:
to:
If you want to export an initialized Firebase SDK for use elsewhere, move it to its own file called
functions\src\firebase.ts
(or similar):then use it like so: