javascript - 云功能停止执行
问题描述
所以我创建了一个函数来处理 Paypal 即时付款通知(IPN)。收到通知一切顺利,当我请求返回 Paypal 进行验证时,我也收到了“已验证”消息。问题是云函数在验证函数回调中没有或停止执行。
exports.ipnHandler = functions.https.onRequest((req, res) => {
console.log("IPN Notification Event Received");
if (req.method !== "POST") {
console.error("Request method not allowed.");
res.status(405).send("Method Not Allowed");
} else {
// Return empty 200 response to acknowledge IPN post success.
console.log("IPN Notification Event received successfully.");
// JSON object of the IPN message consisting of transaction details.
let ipnTransactionMessage = req.body;
// Convert JSON ipn data to a query string since Google Cloud Function does not expose raw request data.
let formUrlEncodedBody = querystring.stringify(ipnTransactionMessage);
// Build the body of the verification post message by prefixing 'cmd=_notify-validate'.
let verificationBody = `cmd=_notify-validate&${formUrlEncodedBody}`;
console.log(`Verifying IPN: ${verificationBody}`);
let options = {
method: "POST",
url: getPaypalURI(),
body: verificationBody,
};
requestPromise(options)
.then(body => {
// This will log "VERIFIED"
console.log(body); // Cloud function stops here
if (body === "VERIFIED") {
console.log("Manage user subscription");
const transactionType = ipnTransactionMessage.txn_type;
const invoice = ipnTransactionMessage.invoice;
const docRef = firestore.collection("users");
console.log("Transaction type: " + transactionType);
console.log("Invoice " + invoice);
if (transactionType === "subscr_payment") {
console.log("About to subscribe user: " + invoice);
return docRef.where("invoice", "==", invoice).get();
}
}
return console.log("Request completed");
})
.then(snapshots => {
return console.log("Return snapshots " + snapshots);
})
.catch(error => {
console.log(error);
})
res.status(200).end();
}
当我添加这一行时,它开始出现异常。return docRef.where("invoice", "==", invoice).get();
据说它会在下面的回调中返回快照数据。
.then(snapshots => {
return console.log("Return snapshots " + snapshots);
})
解决方案
我已经解决了这个问题。似乎该函数已达到超时,默认为 60 秒。我只是将超时更改为 5 分钟。
推荐阅读
- php - 无法使用 Doctrine ORM 生成我的数据库(找不到驱动程序)
- python - Python,排序函数:按值排序字典返回意外列表
- flutter - Flutter如何检查WIFI是否打开(连接与否无所谓)?
- node.js - 无法在 express js 中使用 .env 变量
- laravel - 使用 Laravel 和 Vuejs 使用条码扫描器自动完成搜索
- swagger - 在 Asp.Net Framework WebApi 中使用 Swashbuckle 生成 Swagger OpenApi Spec 3.0
- webclient - 在返回之前订阅 Mono 是一个好的模式吗?
- php - 在php,mysql中插入记录重复
- javascript - 通过网络服务器上的脚本从客户端浏览器向本地 URL/IP 发送请求
- excel - Excel 搜索 - 发现多个单词以逗号分隔打印