diff --git a/workflows/quickstart/index.js b/workflows/quickstart/index.js index 9c8faf5e39..490622da05 100644 --- a/workflows/quickstart/index.js +++ b/workflows/quickstart/index.js @@ -19,6 +19,7 @@ const projectId = process.argv[2] || process.env.GOOGLE_CLOUD_PROJECT; const location = process.argv[3] || 'us-central1'; const workflowName = process.argv[4] || 'myFirstWorkflow'; +const searchTerm = process.argv[5] || null; // [START workflows_api_quickstart] const {ExecutionsClient} = require('@google-cloud/workflows'); @@ -30,12 +31,14 @@ const client = new ExecutionsClient(); // const projectId = 'my-project'; // const location = 'us-central1'; // const workflow = 'myFirstWorkflow'; +// const searchTerm = null; /** * Executes a Workflow and waits for the results with exponential backoff. * @param {string} projectId The Google Cloud Project containing the workflow * @param {string} location The workflow location * @param {string} workflow The workflow name + * @param {string} searchTerm Optional search term to pass as runtime argument to Workflow */ async function executeWorkflow(projectId, location, workflow) { /** @@ -50,10 +53,12 @@ async function executeWorkflow(projectId, location, workflow) { // Execute workflow try { + const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {}; const createExecutionRes = await client.createExecution({ parent: client.workflowPath(projectId, location, workflow), execution: { - argument: JSON.stringify({}), + // Provide runtime arguments as a JSON string + argument: JSON.stringify(runtimeArgs), }, }); const executionName = createExecutionRes[0].name; diff --git a/workflows/quickstart/index.ts b/workflows/quickstart/index.ts index 89c007d121..d82725a439 100644 --- a/workflows/quickstart/index.ts +++ b/workflows/quickstart/index.ts @@ -16,6 +16,7 @@ const projectId = process.argv[2] || (process.env.GOOGLE_CLOUD_PROJECT as string); const location = process.argv[3] || 'us-central1'; const workflowName = process.argv[4] || 'myFirstWorkflow'; +const searchTerm = process.argv[5] || null; // [START workflows_api_quickstart] import {ExecutionsClient} from '@google-cloud/workflows'; @@ -27,12 +28,14 @@ const client: ExecutionsClient = new ExecutionsClient(); // const projectId = 'my-project'; // const location = 'us-central1'; // const workflow = 'myFirstWorkflow'; +// const searchTerm = null; /** * Executes a Workflow and waits for the results with exponential backoff. * @param {string} projectId The Google Cloud Project containing the workflow * @param {string} location The workflow location * @param {string} workflow The workflow name + * @param {string} searchTerm Optional search term to pass as runtime argument to Workflow */ async function executeWorkflow( projectId: string, @@ -51,10 +54,12 @@ async function executeWorkflow( // Execute workflow try { + const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {}; const createExecutionRes = await client.createExecution({ parent: client.workflowPath(projectId, location, workflow), execution: { - argument: JSON.stringify({}), + // Provide runtime arguments as a JSON string + argument: JSON.stringify(runtimeArgs), }, }); const executionName = createExecutionRes[0].name;