小程序云函数如何执行超过59秒的耗时操作?
希望调用云函数成功后就返回 ctx.body = { data: "Success" };
然后继续执行 chatAi()。
现在遇到的问题是返回后chatAi()不执行了。
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext();
const app = new TcbRouter({ event });
app.use(async (ctx, next) => {
ctx.data = {};
await next();
});
app.router("UpdateReport", async (ctx, next) => {
try {
const { access_token } = await queryAccessToken();
const {
user_id,
reports_id,
category_id,
output,
reports_type,
categorys,
text: extract,
date,
} = event.value;
const object = {
access_token,
type: reports_type,
output,
input: extract || "",
};
ctx.body = { data: "Success" };
chatAi(
"https://zrmprpsglplhnhyeh.lambda-url.ap-southeast-1.on.aws/",
object
);
} catch (error) {
console.error("Error in UpdateReport:", error);
ctx.body = { data: error };
}
});
async function chatAi(url, object) {
try {
await axios.post(url, object);
} catch (error) {
throw new Error("error" + error);
}
}
return app.serve();
};
可以调整下函数超时时间