gpt4 book ai didi

javascript - 从 Cloud Function 触发 Cloud Dataflow 管道 - 函数超时

转载 作者:行者123 更新时间:2023-11-30 11:22:15 24 4
gpt4 key购买 nike

我正在尝试从 Cloud Functions 触发数据流管道,它本身是在 GCS 存储桶中上传新文件时触发的。当我上传文件时,云功能被正确触发,但几秒钟后超时,没有触发任何数据流。下面是我的函数代码:

const google = require('googleapis');
const projectId = "iot-fitness-198120";

exports.moveDataFromGCStoPubSub = function(event, callback) {
const file = event.data;
if (file.resourceState === 'exists' && file.name) {
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}

if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
]);
}
console.log("File exists and client function is authenticated");
console.log(file);


const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
console.log(`Incoming data: ${file.name}`);

dataflow.projects.templates.create({
projectId: projectId,
resource: {
parameters: {
inputFile: `gs://${file.bucket}/${file.name}`,
outputTopic: `projects/iot-fitness-198120/topics/MemberFitnessData`
},
jobName: 'CStoPubSub',
gcsPath: 'gs://dataflow-templates/latest/GCS_Text_to_Cloud_PubSub',
staginglocation: 'gs://fitnessanalytics-tmp/tmp'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});

});
}
};

执行甚至不会记录以下行,console.log("File exists and client function is authenticated");这告诉我它甚至还没有走到那一步。

这是执行过程中的日志输出:

2018-03-20 04:56:43.283 消费税数据流触发函数52957909906492函数执行耗时 60097 毫秒,完成状态:“超时”

2018-03-20 04:55:43.188 消费税数据流触发函数52957909906492函数执行开始

知道为什么它不触发数据流但不抛出错误消息吗?

最佳答案

我终于修改了代码。从 GCP 支持获得了一些帮助。以下是有效的正确语法:

var {google} = require('googleapis');

exports.moveDataFromGCStoPubSub = (event, callback) => {


const file = event.data;
const context = event.context;

console.log(`Event ${context.eventId}`);
console.log(` Event Type: ${context.eventType}`);
console.log(` Bucket: ${file.bucket}`);
console.log(` File: ${file.name}`);
console.log(` Metageneration: ${file.metageneration}`);
console.log(` Created: ${file.timeCreated}`);
console.log(` Updated: ${file.updated}`);

google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}

console.log(projectId);

const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
console.log(`gs://${file.bucket}/${file.name}`);
dataflow.projects.templates.create({
gcsPath: 'gs://dataflow-templates/latest/GCS_Text_to_Cloud_PubSub',
projectId: projectId,
resource: {
parameters: {
inputFilePattern: `gs://${file.bucket}/${file.name}`,
outputTopic: 'projects/iot-fitness-198120/topics/MemberFitnessData2'
},
environment: {
tempLocation: 'gs://fitnessanalytics-tmp/tmp'
},
jobName: 'CStoPubSub',
//gcsPath: 'gs://dataflow-templates/latest/GCS_Text_to_Cloud_PubSub',
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});

});

callback();
};

关于javascript - 从 Cloud Function 触发 Cloud Dataflow 管道 - 函数超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49379756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com