Skip to content

Commit 46e0ab7

Browse files
committed
ci: address comments
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent a0ce45a commit 46e0ab7

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

workflows/cloud-client/pom.xml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
12
<!--
2-
Copyright 2018, Google Inc.
3+
Copyright 2021, Google LLC
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.
56
You may obtain a copy of the License at
@@ -10,10 +11,10 @@
1011
See the License for the specific language governing permissions and
1112
limitations under the License.
1213
-->
13-
<project>
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1415
<modelVersion>4.0.0</modelVersion>
15-
<groupId>com.example.texttospeech</groupId>
16-
<artifactId>tts-samples</artifactId>
16+
<groupId>com.example.workflows</groupId>
17+
<artifactId>workflows-quickstart</artifactId>
1718
<packaging>jar</packaging>
1819

1920
<!--
@@ -40,7 +41,7 @@
4041
<dependency>
4142
<groupId>com.google.cloud</groupId>
4243
<artifactId>libraries-bom</artifactId>
43-
<version>20.4.0</version>
44+
<version>20.6.0</version>
4445
<type>pom</type>
4546
<scope>import</scope>
4647
</dependency>

workflows/cloud-client/src/main/java/com/example/workflows/WorkflowsQuickstart.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google Inc.
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,13 @@
2020

2121
// Imports the Google Cloud client library
2222

23+
import com.google.cloud.workflows.executions.v1.CreateExecutionRequest;
2324
import com.google.cloud.workflows.executions.v1.Execution;
2425
import com.google.cloud.workflows.executions.v1.ExecutionsClient;
2526
import com.google.cloud.workflows.executions.v1.WorkflowName;
2627

28+
import java.io.IOException;
29+
2730
/**
2831
* Cloud Workflows API sample. Executes a workflow and waits for results.
2932
* Example usage:
@@ -35,11 +38,13 @@ public class WorkflowsQuickstart {
3538
private static String LOCATION = System.getenv("LOCATION");
3639
private static String WORKFLOW = System.getenv("WORKFLOW");
3740

38-
public static String workflowsQuickstart(String projectId, String location, String workflow) {
41+
public static String workflowsQuickstart(String projectId, String location, String workflow) throws InterruptedException, IOException {
3942
// Execute workflow
4043
try (ExecutionsClient workflowExecutionsClient = ExecutionsClient.create()) {
4144
WorkflowName parent = WorkflowName.of(projectId, location, workflow);
4245
Execution initialExecution = Execution.newBuilder().build();
46+
47+
// Creates the execution object.
4348
Execution createExecutionRes = workflowExecutionsClient
4449
.createExecution(parent, initialExecution);
4550

@@ -49,11 +54,17 @@ public static String workflowsQuickstart(String projectId, String location, Stri
4954
// Wait for execution to finish, then print results.
5055
boolean executionFinished = false;
5156
long backoffDelay = 1_000; // Start wait with delay of 1,000 ms
57+
final long BACKOFF_TIMEOUT = 10 * 60_000; // Time out at 10 minutes
5258
System.out.println("Poll for results...");
5359
while (!executionFinished) {
5460
Execution execution = workflowExecutionsClient.getExecution(executionName);
5561
executionFinished = execution.getState() != Execution.State.ACTIVE;
5662

63+
// We've passed the max
64+
if (backoffDelay > BACKOFF_TIMEOUT) {
65+
return "";
66+
}
67+
5768
// If we haven't seen the results yet, wait.
5869
if (!executionFinished) {
5970
System.out.println("- Waiting for results");
@@ -65,18 +76,14 @@ public static String workflowsQuickstart(String projectId, String location, Stri
6576
return execution.getResult();
6677
}
6778
}
68-
// This return is never reached.
69-
return "";
70-
} catch (Exception e) {
71-
System.out.printf("Error executing workflow: %s%n", e);
72-
return "";
7379
}
80+
return "";
7481
}
7582

7683
/**
7784
* Demonstrates using the Workflows API.
7885
*/
79-
public static void main(String... args) {
86+
public static void main(String... args) throws IOException, InterruptedException {
8087
if (GOOGLE_CLOUD_PROJECT.isEmpty()) {
8188
System.out.println("GOOGLE_CLOUD_PROJECT is empty");
8289
}

workflows/cloud-client/src/test/java/com/example/workflows/WorkflowsQuickstartTest.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google Inc.
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,14 @@
2020
import static org.junit.Assert.assertNotEquals;
2121
import static org.junit.Assert.assertNotNull;
2222

23+
import com.google.api.gax.longrunning.OperationFuture;
24+
import com.google.cloud.workflows.v1.OperationMetadata;
2325
import com.google.cloud.workflows.v1.Workflow;
2426
import com.google.cloud.workflows.v1.WorkflowName;
2527
import com.google.cloud.workflows.v1.WorkflowsClient;
2628
import java.io.IOException;
29+
import java.util.concurrent.ExecutionException;
30+
2731
import org.junit.BeforeClass;
2832
import org.junit.Test;
2933

@@ -48,9 +52,7 @@ public static void beforeClass() {
4852
}
4953

5054
@Test
51-
public void testQuickstart() throws IOException, InterruptedException {
52-
System.out.println("testing!!");
53-
55+
public void testQuickstart() throws IOException, InterruptedException, ExecutionException {
5456
// Deploy the workflow
5557
deployWorkflow(projectId, LOCATION_ID, WORKFLOW_ID);
5658

@@ -63,17 +65,16 @@ public void testQuickstart() throws IOException, InterruptedException {
6365
}
6466

6567
private boolean deployWorkflow(String projectId, String location, String workflowId)
66-
throws IOException, InterruptedException {
68+
throws IOException, InterruptedException, ExecutionException {
6769
// Create a new workflow if it doesn't exist
68-
if (!workflowExists(projectId, location, workflowId)) {
70+
// if (!workflowExists(projectId, location, workflowId)) {
6971
System.out.println("START DEPLOY");
7072
WorkflowsClient workflowsClient = WorkflowsClient.create();
7173
// Deploy workflow
7274
Workflow workflow = Workflow.newBuilder()
7375
.setName(workflowId)
7476
.setSourceContents(WORKFLOW_SOURCE)
7577
.build();
76-
workflowsClient.createWorkflowAsync(location, workflow, workflowId);
7778

7879
// Wait until workflow is active
7980
Workflow deployedWorkflow = null;
@@ -93,8 +94,6 @@ private boolean deployWorkflow(String projectId, String location, String workflo
9394

9495
// Return true if the workflow is now active
9596
return deployedWorkflow.getState() != Workflow.State.ACTIVE;
96-
}
97-
return false;
9897
}
9998

10099
/**

0 commit comments

Comments
 (0)