Skip to content

Commit 815d72c

Browse files
rogerthatdevgcf-owl-bot[bot]pattishin
authored
refactor(workflows): change how runtimeArgs are defined in workflows quickstart (GoogleCloudPlatform#3461)
* define runtimeArgs outside of execute function * add runtimeargs as execute function param * add missing param * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint * typo * give runtime args default values * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * reincorporate searchTerm param into function * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update var description one more time * somehow forgot to type the typescript * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * forgot to readd the new region tag * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * indent * remove region tags from this PR * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * rm runtime args tags from ts too * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add type * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * move json stringify * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add execution and libraries region tags * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint * add type * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add type again again * 🦉 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: Patti Shin <pattishin@users.noreply.github.com>
1 parent 5383ced commit 815d72c

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

workflows/quickstart/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,29 @@
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;
22+
const searchTerm = process.argv[5] || '';
2323

2424
// [START workflows_api_quickstart]
25+
// [START workflows_api_quickstart_client_libraries]
2526
const {ExecutionsClient} = require('@google-cloud/workflows');
2627
const client = new ExecutionsClient();
27-
28+
// [END workflows_api_quickstart_client_libraries]
2829
/**
2930
* TODO(developer): Uncomment these variables before running the sample.
3031
*/
3132
// const projectId = 'my-project';
3233
// const location = 'us-central1';
3334
// const workflow = 'myFirstWorkflow';
34-
// const searchTerm = null;
35+
// const searchTerm = '';
3536

3637
/**
3738
* Executes a Workflow and waits for the results with exponential backoff.
3839
* @param {string} projectId The Google Cloud Project containing the workflow
3940
* @param {string} location The workflow location
4041
* @param {string} workflow The workflow name
41-
* @param {string} searchTerm Optional search term to pass as runtime argument to Workflow
42+
* @param {string} searchTerm Optional search term to pass to the Workflow as a runtime argument
4243
*/
43-
async function executeWorkflow(projectId, location, workflow) {
44+
async function executeWorkflow(projectId, location, workflow, searchTerm) {
4445
/**
4546
* Sleeps the process N number of milliseconds.
4647
* @param {Number} ms The number of milliseconds to sleep.
@@ -50,14 +51,14 @@ async function executeWorkflow(projectId, location, workflow) {
5051
setTimeout(resolve, ms);
5152
});
5253
}
53-
54+
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
55+
// [START workflows_api_quickstart_execution]
5456
// Execute workflow
5557
try {
56-
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
5758
const createExecutionRes = await client.createExecution({
5859
parent: client.workflowPath(projectId, location, workflow),
5960
execution: {
60-
// Provide runtime arguments as a JSON string
61+
// Runtime arguments can be passed as a JSON string
6162
argument: JSON.stringify(runtimeArgs),
6263
},
6364
});
@@ -88,10 +89,12 @@ async function executeWorkflow(projectId, location, workflow) {
8889
} catch (e) {
8990
console.error(`Error executing workflow: ${e}`);
9091
}
92+
// [END workflows_api_quickstart_execution]
9193
}
9294

93-
executeWorkflow(projectId, location, workflowName).catch(err => {
95+
executeWorkflow(projectId, location, workflowName, searchTerm).catch(err => {
9496
console.error(err.message);
9597
process.exitCode = 1;
9698
});
99+
97100
// [END workflows_api_quickstart]

workflows/quickstart/index.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@ 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;
19+
const searchTerm = process.argv[5] || '';
2020

2121
// [START workflows_api_quickstart]
22+
// [START workflows_api_quickstart_client_libraries]
2223
import {ExecutionsClient} from '@google-cloud/workflows';
2324
const client: ExecutionsClient = new ExecutionsClient();
24-
25+
// [END workflows_api_quickstart_client_libraries]
2526
/**
2627
* TODO(developer): Uncomment these variables before running the sample.
2728
*/
2829
// const projectId = 'my-project';
2930
// const location = 'us-central1';
3031
// const workflow = 'myFirstWorkflow';
31-
// const searchTerm = null;
32+
// const searchTerm = '';
3233

3334
/**
3435
* Executes a Workflow and waits for the results with exponential backoff.
3536
* @param {string} projectId The Google Cloud Project containing the workflow
3637
* @param {string} location The workflow location
3738
* @param {string} workflow The workflow name
38-
* @param {string} searchTerm Optional search term to pass as runtime argument to Workflow
39+
* @param {string} searchTerm Optional search term to pass to the Workflow as a runtime argument
3940
*/
4041
async function executeWorkflow(
4142
projectId: string,
4243
location: string,
43-
workflow: string
44+
workflow: string,
45+
searchTerm: string
4446
) {
4547
/**
4648
* Sleeps the process N number of milliseconds.
@@ -51,14 +53,14 @@ async function executeWorkflow(
5153
setTimeout(resolve, ms);
5254
});
5355
}
54-
56+
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
57+
// [START workflows_api_quickstart_execution]
5558
// Execute workflow
5659
try {
57-
const runtimeArgs = searchTerm ? {searchTerm: searchTerm} : {};
5860
const createExecutionRes = await client.createExecution({
5961
parent: client.workflowPath(projectId, location, workflow),
6062
execution: {
61-
// Provide runtime arguments as a JSON string
63+
// Runtime arguments can be passed as a JSON string
6264
argument: JSON.stringify(runtimeArgs),
6365
},
6466
});
@@ -89,10 +91,13 @@ async function executeWorkflow(
8991
} catch (e) {
9092
console.error(`Error executing workflow: ${e}`);
9193
}
94+
// [END workflows_api_quickstart_execution]
9295
}
9396

94-
executeWorkflow(projectId, location, workflowName).catch((err: Error) => {
95-
console.error(err.message);
96-
process.exitCode = 1;
97-
});
97+
executeWorkflow(projectId, location, workflowName, searchTerm).catch(
98+
(err: Error) => {
99+
console.error(err.message);
100+
process.exitCode = 1;
101+
}
102+
);
98103
// [END workflows_api_quickstart]

0 commit comments

Comments
 (0)