This quickstart shows you how to execute a workflow and view execution results
using a client library. The sample assumes you have deployed the workflow,
myFirstWorkflow
using the Cloud Console
or the gcloud
command-line tool first.
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
Enable the Workflows API.
Enable the Workflows API-
In the Cloud Console, go to the Service accounts page.
Go to the Create Service Account page - Select Create service account.
- In the Service account name field, enter a name.
- Click Create.
From the Role list, select Logging >Logs Writer.
Note: The Role field authorizes your service account to access resources. To send logs to Cloud Logging, assign theroles/logging.logWriter
role. If you are developing a production app, always grant the least permissive roles possible. For more information, see granting roles to service accounts. For a list of Workflows roles, see the Access control reference.- Click Continue.
- Click Done.
Get the sample code
Clone the sample repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
Change to the directory that contains the Cloud Functions sample code:
cd nodejs-docs-samples/workflows/quickstart/
Review the sample code:
The program does the following:
- Sets up the Workflows client libraries.
- Executes a workflow.
- Polls the workflow's execution (using exponential backoff) until the execution terminates.
- Prints the execution results.
Install dependencies
npm install
Run the sample
To run the sample, run the following script:
node . PROJECT_ID [CLOUD_REGION] [WORKFLOW_NAME]
Replace the following command-line arguments:
PROJECT_ID
(required): Project ID of the Cloud Platform projectCLOUD_REGION
: Cloud location for the workflow (default:us-central1
)WORKFLOW_NAME
: ID of the workflow (default:myFirstWorkflow
)
For example:
node . my-custom-project us-central1 userSignupWorkflow
Example output:
Execution finished with state: SUCCEEDED
["Sunday","Sunday in the Park with George","Sunday shopping","Sunday Bloody Sunday","Sunday Times Golden Globe Race","Sunday All Stars","Sunday Night (South Korean TV series)","Sunday Silence","Sunday Without God","Sunday Independent (Ireland)"]
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.
Go to the Workflows page in the Cloud Console.
WorkflowsSelect the Delete button.
In the prompt that appears, enter the name of the workflow.
Select Delete.