Skip to content

Commit

Permalink
samples: automl: explictly update timeoutes due to default library ch…
Browse files Browse the repository at this point in the history
…anges (#2719)

* automl: explictly update timeoutes due to library changes in the defaults

* Update ImportDataset.java

* try bumping timeout

AutoML provides no guarantee on how long this could take and normally would send an email followup. Though normally, I see this finish in under 10 mins. Trying to pin down if TASK CANCELLED is actually related to a timeout or not.

* update timeouts for all import methods

* undo changes to TablesImport, add catch for Cancellation Exception

* update to correct CancelledException

* wrong cancellation again

* run tests

* log to error

* test

* reset changes that printed error

* set retry settings

* add timeout check to beta code
  • Loading branch information
nnegrey authored and chingor13 committed Aug 3, 2020
1 parent 1cdcca0 commit 4624473
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@
package com.example.automl;

// [START automl_import_dataset]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.DatasetName;
import com.google.cloud.automl.v1.GcsSource;
import com.google.cloud.automl.v1.InputConfig;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

class ImportDataset {

public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String datasetId = "YOUR_DATASET_ID";
Expand All @@ -39,7 +43,7 @@ public static void main(String[] args)

// Import a dataset
static void importDataset(String projectId, String datasetId, String path)
throws IOException, ExecutionException, InterruptedException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
Expand All @@ -55,8 +59,22 @@ static void importDataset(String projectId, String datasetId, String path)
InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
System.out.println("Processing import...");

Empty response = client.importDataAsync(datasetFullId, inputConfig).get();
System.out.format("Dataset imported. %s\n", response);
// Start the import job
OperationFuture<Empty, OperationMetadata> operation =
client.importDataAsync(datasetFullId, inputConfig);

System.out.format("Operation name: %s%n", operation.getName());

// If you want to wait for the operation to finish, adjust the timeout appropriately. The
// operation will still run if you choose not to wait for it to complete. You can check the
// status of your operation using the operation's name.
Empty response = operation.get(45, TimeUnit.MINUTES);
System.out.format("Dataset imported. %s%n", response);
} catch (TimeoutException e) {
System.out.println("The operation's polling period was not long enough.");
System.out.println("You can use the Operation's name to get the current status.");
System.out.println("The import job is still running and will complete as expected.");
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -83,7 +84,8 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
}

@Test
public void testImportDataset() throws IOException, ExecutionException, InterruptedException {
public void testImportDataset()
throws IOException, ExecutionException, InterruptedException, TimeoutException {
ImportDataset.importDataset(PROJECT_ID, datasetId, BUCKET + "/entity-extraction/dataset.csv");
String got = bout.toString();
assertThat(got).contains("Dataset imported.");
Expand Down

0 comments on commit 4624473

Please sign in to comment.