【发布时间】:2021-01-13 22:31:15
【问题描述】:
这是我的谷歌云功能:
async function getPSQLdata() {
const pg = require('pg');
var pgConfig = {
user: 'postgres',
password: '[MY PASSWORD]',
database: '[MY DB NAME]',
host: '[PUBLIC IP ADDRESS OF DB INSTANCE]'
};
var pgPool;
if (!pgPool) {
pgPool = new pg.Pool(pgConfig);
}
const scores = await pgPool
.query("SELECT * from table")
.then(res => console.log(res.rows[0]))
.catch(e => console.error(e.stack));
}
exports.dailyFill = async function main() {
await getPSQLdata();
};
Google Cloud Logging 说:“函数执行耗时 60003 毫秒,完成状态:‘超时’”。
到目前为止我所尝试的:
- 我已在 GCP 项目中启用 Cloud SQL Admin API
- 我已在 GCP 项目中启用 Cloud SQL API
- 我已将 Google Cloud Function 服务帐号作为“Cloud SQL 客户端”和“项目编辑器”角色添加到 IAM
【问题讨论】:
-
你的函数应该返回一个promise,否则它会超时。将
getPSQLdata中的最后一条语句更改为return pgPool.query("SELECT * from table").then(res =>console.log(res.rows[0])).catch(e => console.error(e.stack));并将此函数导出为exports.dailyFill = getPSQLdata -
谢谢。 “将这个函数导出为exports.dailyFill = getPSQLdata”是什么意思?
标签: postgresql google-cloud-platform google-cloud-functions google-cloud-sql