This article解释了如何通过 Cloud Functions 执行用 Java 编写的管道。但是,我正在尝试使用用 python 编写的管道来完成此操作。
在使用 python 的 virtualenv 环境执行本地 Cloud Function 时,我能够成功地做到这一点。这是在打包为 zip 之前。
exports.foo = function(event, callback) {
var spawn = require('child_process').spawn;
var child = spawn(
'ENV/bin/python',
["pipeline.py",
"--project $PROEJCT_ID",
"--temp_location gs://$BUCKET/temp",
"--staging_location gs://$BUCKET/staging",
"--runner DataflowRunner"],
{cwd: __dirname}
);
child.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
child.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
child.on('close', (code) => {
console.log(`child process exited with code ${code}`);
callback();
});
};
但是,当我将函数实际部署到 GCP 并从那里运行时,管道永远不会执行。
如有任何见解,我们将不胜感激。
以下是运行已部署函数时的日志:
D foo vxvt93uc415v 2017-03-05 00:56:43.639 Function execution started
D foo vxvt93uc415v 2017-03-05 00:56:57.945 Function execution took 14308 ms, finished with status: 'ok'
更新:
出现错误,我没有正确注销:
ENV/bin/python is not a supported ELF or interpreter script
我已经联系了 Cloud Functions 团队,他们随后提交了错误报告。
最佳答案
我在为 MacOS 编译的二进制文件中遇到了同样的问题。云函数容器使用 Debian,linux 和 MacOS 可执行文件不兼容(参见 https://stackoverflow.com/a/9439548 )。
我安装了 Cloud functions docker container ,并在容器内下载并编译我需要的二进制文件,然后将其复制出容器并使用云功能进行部署。但是在您的案例中,您可能只需使用预编译的 Debian 兼容 python 解释器就可以逃脱。
关于python - 如何通过 Cloud Functions 调度用 Python 编写的 Dataflow 管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42603832/