在 Nodejs 中执行谷歌云工作流时如何包含运行时参数?

问题描述

我正在尝试在执行谷歌云工作流程时包含运行时变量。除非您使用 REST API,否则我找不到相关文档。

这是我的代码,主要来自他们的文档,我只是为参数获取了空值。我认为它可能是它在 createExecution 命名执行上期望的第二个参数的东西,但我无法弄清楚。

const { ExecutionsClient } = require('@google-cloud/workflows');

const client = new ExecutionsClient();

const execute = () => {
  return client.createExecution(
    {
      parent: client.workflowPath('project_id','location','name'),},{
      argument: {
        users: ['info here'],);
};

module.exports = execute;

感谢您的帮助!

解决方法

如果其他人遇到此问题,您可以将参数执行与 parent 一起传递给 createExecution()。它只是一个对象,您可以在那里指定带有字符串的参数。将您的对象字符串化,您就可以开始了!

const { ExecutionsClient } = require('@google-cloud/workflows');

const client = new ExecutionsClient();

const execute = () => {
  return client.createExecution({
    parent: client.workflowPath('','',''),execution: {
      argument: JSON.stringify({
        users: [],}),},});
};

module.exports = execute;