1919const projectId = process . argv [ 2 ] || process . env . GOOGLE_CLOUD_PROJECT ;
2020const location = process . argv [ 3 ] || 'us-central1' ;
2121const 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]
2526const { ExecutionsClient} = require ( '@google-cloud/workflows' ) ;
2627const 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]
0 commit comments