Google cloud storage 多次触发Google云存储对象最终确定事件

Google cloud storage 多次触发Google云存储对象最终确定事件,google-cloud-storage,google-cloud-functions,Google Cloud Storage,Google Cloud Functions,场景 我有几个Google Cloud函数是由Google Cloud Storage object.finalize事件触发的。为此,我使用了两个bucket,并使用“同步选项:覆盖目标位置的对象””传输作业,该选项每天将单个文件从一个源bucket复制到目标位置。两个函数的源存储桶相同,而目标存储桶不同 问题 大多数情况下,它都能按预期工作,但有时我几乎同时看到多个事件。大多数情况下,我看到2个重复,但有一次是3个。我输入了日志事件负载,但它总是一样的 更多详细信息 问题 这可能是谷歌云存

场景

我有几个Google Cloud函数是由Google Cloud Storage object.finalize事件触发的。为此,我使用了两个bucket,并使用“同步选项:覆盖目标位置的对象””传输作业,该选项每天将单个文件从一个源bucket复制到目标位置。两个函数的源存储桶相同,而目标存储桶不同

问题

大多数情况下,它都能按预期工作,但有时我几乎同时看到多个事件。大多数情况下,我看到2个重复,但有一次是3个。我输入了日志事件负载,但它总是一样的

更多详细信息

问题

这可能是谷歌云存储的一个已知问题吗

如果没有,那么我的代码很可能有问题

我使用以下项目结构:

/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代码/executor.js

const utils = require('../shared-code/utils.js)

exports.execute = (event, callback) => {
       // run Big Query foo.sql statement
};
const utils = require('../shared-code/utils.js)

exports.execute = (event, callback) => {
       // run Big Query bar.sql statement
};
/条形码/executor.js

const utils = require('../shared-code/utils.js)

exports.execute = (event, callback) => {
       // run Big Query foo.sql statement
};
const utils = require('../shared-code/utils.js)

exports.execute = (event, callback) => {
       // run Big Query bar.sql statement
};
最后是部署:

foo具有特定bucket触发器的后台功能:

gcloud beta functions deploy foo \
                --source=https://<path_to_repo>/functions \
                --trigger-bucket=foo-destination-bucket \
                --timeout=540 \
                --memory=128MB
gcloud beta functions deploy bar \
                --source=https://<path_to_repo>/functions \
                --trigger-bucket=bar-destination-bucket \
                --timeout=540 \
                --memory=128MB
gcloud测试版函数部署foo\
--来源=https:///functions \
--触发桶=foo目标桶\
--超时=540\
--内存=128MB
具有特定铲斗触发器的后台功能:

gcloud beta functions deploy foo \
                --source=https://<path_to_repo>/functions \
                --trigger-bucket=foo-destination-bucket \
                --timeout=540 \
                --memory=128MB
gcloud beta functions deploy bar \
                --source=https://<path_to_repo>/functions \
                --trigger-bucket=bar-destination-bucket \
                --timeout=540 \
                --memory=128MB
gcloud测试版函数部署栏\
--来源=https:///functions \
--触发桶=条形目标桶\
--超时=540\
--内存=128MB

对我来说,最可能的问题是由于多个部署的事实(只有触发器bucket标志不同)。但奇怪的是,上面的设置大部分时间都在工作

云函数的正常行为是,至少在事件被传递和后台函数被调用之后,这意味着很少会出现虚假的重复

要确保函数在重试执行尝试时正确运行,应通过实现它使其幂等,以便即使多次传递事件也能产生所需的结果(和副作用)


查看文档中的一些信息。

是的,我同意。使函数调用幂等是qlear的解决方案。但在我的例子中,我需要更新大查询表,我不知道是否可以检查某个进程/作业是否正在运行或几秒钟前刚刚完成。好的,我看到可能可以在事务模式下查询DB,我的问题将得到解决。感谢您澄清可以进行多次调用。如果我理解正确,您可以使用Stackdriver logging或status.state检查作业是否完成。