如果我没有在无服务器函数结束时关闭数据库连接,我的脚本将挂起并超时。
我希望有一种方法可以在我的任何无服务器功能结束时运行清理功能,这将关闭活动的数据库连接等。
module.exports.create = (event, context, callback) => {
user.insert({
//user details
}).then((results) => {
responseHelper.success(JSON.stringify(results), callback);
}, (error) => {
// Connection error
responseHelper.error(error, callback);
});
// I don't want to have this at the end of every function
// I'd rather run it in a cleanup step which runs on all functions
db.closeConnections();
}