장기 실행 작업 (LRO)

API를 여러 번 호출하면 장기 실행 작업이 반환됩니다. 이는 장시간 실행되는 작업의 상태를 추적하므로 차단 RPC가 있는 것이 바람직하지 않습니다.

OperationFuture 클래스

LRO와 상호작용하는 가장 명확한 방법은 OperationFuture 클래스를 사용하는 것입니다. 이를 사용하는 경우 서비스 클라이언트가 소멸되지 않았는지 확인합니다.

다음은 권장하지 않습니다.

private void doSomething() {
  OperationFuture<Empty, Empty> future = startLongRunningOperation(jobName);
  future.get();
}

private OperationFuture<Empty, Empty> startLongRunningOperation(String jobToStart)
    throws UnsupportedEncodingException {
  try (OfflineUserDataJobServiceClient offlineUserDataJobServiceClient =
      googleAdsClient.getLatestVersion().createOfflineUserDataJobServiceClient()) {
    // Issues an asynchronous request to run the offline user data job for executing
    // all added operations.
    return offlineUserDataJobServiceClient.runOfflineUserDataJobAsync(jobToStart);
  }
}

다음을 권장합니다.

private void doSomethingElse() {
  try (OfflineUserDataJobServiceClient offlineUserDataJobServiceClient =
      googleAdsClient.getLatestVersion().createOfflineUserDataJobServiceClient()) {
    OperationFuture<Empty, Empty> future = startLongRunningOperation(offlineUserDataJobServiceClient, jobName);
    future.get();
  }
}

private OperationFuture<Empty, Empty> startLongRunningOperation(String jobToStart)
    throws UnsupportedEncodingException {
    offlineUserDataJobServiceClient.runOfflineUserDataJobAsync(jobToStart);
}

OfflineUserDataJobServiceClient가 범위 내에 있는 동안에만 OperationFuture 클래스가 어떻게 사용되는지 확인하세요.