I am trying Vertex AI's Java api. For some long running task like import data, normally it will run about 30 minutes. During this period, is that possible to track progress like percentage of data imported?
My code is like following:
fun importDataSample(
project: String?, datasetName: String?, gcsSourceUri: String?, importSchemaUri: String?
) {
val datasetServiceSettings: DatasetServiceSettings = DatasetServiceSettings.newBuilder()
.setEndpoint("us-central1-aiplatform.googleapis.com:443")
.setCredentialsProvider(credentialsProvider(DatasetServiceSettings.getDefaultServiceScopes()))
.build()
DatasetServiceClient.create(datasetServiceSettings).use { datasetServiceClient ->
val gcsSource = GcsSource.newBuilder()
.addUris(gcsSourceUri)
.build()
val importDataConfig = ImportDataConfig.newBuilder()
.setGcsSource(gcsSource)
.setImportSchemaUri(importSchemaUri)
.build()
val importDataConfigs = ArrayList<ImportDataConfig>()
importDataConfigs.add(importDataConfig)
val importFuture: OperationFuture<ImportDataResponse, ImportDataOperationMetadata> =
datasetServiceClient.importDataAsync(datasetName, importDataConfigs)
System.out.format("Operation name: %s\n", importFuture.getInitialFuture().get().getName())
println("Waiting for operation to finish...")
}
After datasetServiceClient.importDataAsync(datasetName, importDataConfigs), I got a importFuture which is an OperationFuture<ImportDataResponse, ImportDataOperationMetadata>. It contains an initialFuture and a pollingFuture, I've tried various methods of these 3 futures but can't find one works to get the progress.
I've ever found a code at: https://github.com/GoogleCloudPlatform/java-docs-samples/issues/819
In which, something like this:
OperationFuture<LongRunningRecognizeResponse, LongRunningRecognizeMetadata,
Operation> response =
speech.longRunningRecognizeAsync(config, audio);
while (!response.isDone()) {
ApiFuture<LongRunningRecognizeMetadata> future = response.peekMetadata();
if (future != null) {
LongRunningRecognizeMetadata meta = future.get();
if (meta != null) {
int percent = meta.getProgressPercent();
System.out.println(String.format("Percent complete: %s%%", percent));
}
}
Thread.sleep(500);
}
I guess the meta.getProgressPercent() can get what I want. But unfortunately ImportDataOperationMetadata I used doesn't have this method even, so I am stuck now. Any help will be appreciated.
Get percent progress of the long running tasks.