Skip to content

Commit 36a7de8

Browse files
rogerthatdevgcf-owl-bot[bot]kweinmeister
authored
feat(workflows): add runtime arguments to workflows TS sample (#3386)
* feat: allow for providing searchTerm for runtime arguments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Karl Weinmeister <[email protected]>
1 parent 631541c commit 36a7de8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

workflows/quickstart/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const projectId = process.argv[2] || process.env.GOOGLE_CLOUD_PROJECT;
2020
const location = process.argv[3] || 'us-central1';
2121
const workflowName = process.argv[4] || 'myFirstWorkflow';
22+
const searchTerm = process.argv[5] || null;
2223

2324
// [START workflows_api_quickstart]
2425
const {ExecutionsClient} = require('@google-cloud/workflows');
@@ -30,12 +31,14 @@ const client = new ExecutionsClient();
3031
// const projectId = 'my-project';
3132
// const location = 'us-central1';
3233
// const workflow = 'myFirstWorkflow';
34+
// const searchTerm = null;
3335

3436
/**
3537
* Executes a Workflow and waits for the results with exponential backoff.
3638
* @param {string} projectId The Google Cloud Project containing the workflow
3739
* @param {string} location The workflow location
3840
* @param {string} workflow The workflow name
41+
* @param {string} searchTerm Optional search term to pass as runtime argument to Workflow
3942
*/
4043
async function executeWorkflow(projectId, location, workflow) {
4144
/**
@@ -50,10 +53,12 @@ async function executeWorkflow(projectId, location, workflow) {
5053

5154
// Execute workflow
5255
try {
56+
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
5357
const createExecutionRes = await client.createExecution({
5458
parent: client.workflowPath(projectId, location, workflow),
5559
execution: {
56-
argument: JSON.stringify({}),
60+
// Provide runtime arguments as a JSON string
61+
argument: JSON.stringify(runtimeArgs),
5762
},
5863
});
5964
const executionName = createExecutionRes[0].name;

workflows/quickstart/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const projectId =
1616
process.argv[2] || (process.env.GOOGLE_CLOUD_PROJECT as string);
1717
const location = process.argv[3] || 'us-central1';
1818
const workflowName = process.argv[4] || 'myFirstWorkflow';
19+
const searchTerm = process.argv[5] || null;
1920

2021
// [START workflows_api_quickstart]
2122
import {ExecutionsClient} from '@google-cloud/workflows';
@@ -27,12 +28,14 @@ const client: ExecutionsClient = new ExecutionsClient();
2728
// const projectId = 'my-project';
2829
// const location = 'us-central1';
2930
// const workflow = 'myFirstWorkflow';
31+
// const searchTerm = null;
3032

3133
/**
3234
* Executes a Workflow and waits for the results with exponential backoff.
3335
* @param {string} projectId The Google Cloud Project containing the workflow
3436
* @param {string} location The workflow location
3537
* @param {string} workflow The workflow name
38+
* @param {string} searchTerm Optional search term to pass as runtime argument to Workflow
3639
*/
3740
async function executeWorkflow(
3841
projectId: string,
@@ -51,10 +54,12 @@ async function executeWorkflow(
5154

5255
// Execute workflow
5356
try {
57+
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
5458
const createExecutionRes = await client.createExecution({
5559
parent: client.workflowPath(projectId, location, workflow),
5660
execution: {
57-
argument: JSON.stringify({}),
61+
// Provide runtime arguments as a JSON string
62+
argument: JSON.stringify(runtimeArgs),
5863
},
5964
});
6065
const executionName = createExecutionRes[0].name;

0 commit comments

Comments
 (0)