Skip to content

feat(workflows): add runtime arguments to workflows TS sample #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion workflows/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
/**
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion workflows/quickstart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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;
Expand Down