19
19
const projectId = process . argv [ 2 ] || process . env . GOOGLE_CLOUD_PROJECT ;
20
20
const location = process . argv [ 3 ] || 'us-central1' ;
21
21
const workflowName = process . argv [ 4 ] || 'myFirstWorkflow' ;
22
+ const searchTerm = process . argv [ 5 ] || null ;
22
23
23
24
// [START workflows_api_quickstart]
24
25
const { ExecutionsClient} = require ( '@google-cloud/workflows' ) ;
@@ -30,12 +31,14 @@ const client = new ExecutionsClient();
30
31
// const projectId = 'my-project';
31
32
// const location = 'us-central1';
32
33
// const workflow = 'myFirstWorkflow';
34
+ // const searchTerm = null;
33
35
34
36
/**
35
37
* Executes a Workflow and waits for the results with exponential backoff.
36
38
* @param {string } projectId The Google Cloud Project containing the workflow
37
39
* @param {string } location The workflow location
38
40
* @param {string } workflow The workflow name
41
+ * @param {string } searchTerm Optional search term to pass as runtime argument to Workflow
39
42
*/
40
43
async function executeWorkflow ( projectId , location , workflow ) {
41
44
/**
@@ -50,10 +53,12 @@ async function executeWorkflow(projectId, location, workflow) {
50
53
51
54
// Execute workflow
52
55
try {
56
+ const runtimeArgs = searchTerm ? { searchTerm : searchTerm } : { } ;
53
57
const createExecutionRes = await client . createExecution ( {
54
58
parent : client . workflowPath ( projectId , location , workflow ) ,
55
59
execution : {
56
- argument : JSON . stringify ( { } ) ,
60
+ // Provide runtime arguments as a JSON string
61
+ argument : JSON . stringify ( runtimeArgs ) ,
57
62
} ,
58
63
} ) ;
59
64
const executionName = createExecutionRes [ 0 ] . name ;
0 commit comments