tillrohrmann commented on a change in pull request #13217: URL: https://github.com/apache/flink/pull/13217#discussion_r475555137
########## File path: flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java ########## @@ -111,4 +122,41 @@ public static void executeProgram( Thread.currentThread().setContextClassLoader(contextClassLoader); } } + + /** + * This method blocks until the job status is not INITIALIZING anymore. + * If the job is FAILED, it throws an CompletionException with the failure cause. + * @param jobStatusSupplier supplier returning the job status. + */ + public static void waitUntilJobInitializationFinished( + SupplierWithException<JobStatus, Exception> jobStatusSupplier, + SupplierWithException<JobResult, Exception> jobResultSupplier + ) throws CompletionException { + LOG.debug("Wait until job initialization is finished"); + WaitStrategy waitStrategy = new ExponentialWaitStrategy(50, 2000); + try { + JobStatus status = jobStatusSupplier.get(); + long attempt = 0; + while (status == JobStatus.INITIALIZING) { + Thread.sleep(waitStrategy.sleepTime(attempt++)); + status = jobStatusSupplier.get(); + } + if (status == JobStatus.FAILED) { + // note: we can not distinguish between initialization failures and failures once + // execution has started. Execution errors are potentially reported here. + JobResult result = jobResultSupplier.get(); + Optional<SerializedThrowable> throwable = result.getSerializedThrowable(); + if (throwable.isPresent()) { + throw new CompletionException(throwable.get().deserializeError(Thread.currentThread().getContextClassLoader())); Review comment: I think it would be the right approach, yes. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org