【发布时间】:2019-01-28 18:52:50
【问题描述】:
场景
我有几个由 Google Cloud Storage object.finalize 事件触发的 Google Cloud Functions。为此,我使用了两个存储桶并使用“同步选项:覆盖目标位置的对象”传输作业,该作业每天将单个文件从一个源存储桶复制到目标存储桶。两个函数的源存储桶相同,目标存储桶不同。
问题
大部分时间它都按预期工作,但有时我几乎同时看到多个事件。大多数时候,我看到 2 个重复项,但一次是 3 个。我输入了日志事件有效负载,但它始终相同。
更多详情
Here is an example of multiple log entries
问题
这可能是 Google Cloud Storage 的已知问题吗?
如果不是,那么很可能我的代码有问题。
我正在使用以下项目结构:
/functions
|--/foo-code
|--executor.js
|--foo.sql
|--/bar-code
|--executor.js
|--bar.sql
|--/shared-code
|--utils.js
|--index.js
|--package.json
index.js
let foo;
let bar;
exports.foo = (event, callback) => {
console.log(`event ${JSON.stringify(event)}`);
foo = foo || require(`./foo-code/executor`);
foo.execute(event, callback);
};
exports.bar = (event, callback) => {
console.log(`event ${JSON.stringify(event)}`);
bar = bar || require(`./bar-code/executor`);
bar.execute(event, callback);
};
./foo-code/executor.js
const utils = require('../shared-code/utils.js)
exports.execute = (event, callback) => {
// run Big Query foo.sql statement
};
./bar-code/executor.js
const utils = require('../shared-code/utils.js)
exports.execute = (event, callback) => {
// run Big Query bar.sql statement
};
最后是部署:
foo 带有特定桶触发器的后台函数:
gcloud beta functions deploy foo \
--source=https://<path_to_repo>/functions \
--trigger-bucket=foo-destination-bucket \
--timeout=540 \
--memory=128MB
bar带有特定bucket触发器的后台函数:
gcloud beta functions deploy bar \
--source=https://<path_to_repo>/functions \
--trigger-bucket=bar-destination-bucket \
--timeout=540 \
--memory=128MB
在我看来,最可能的问题是由于多个部署的事实(只有 trigger-bucket 标志不同)。但奇怪的是,上述设置大部分时间都有效。
【问题讨论】:
标签: google-cloud-storage google-cloud-functions