private static async Task WaitForRun()

in csharp/Microsoft.Azure.Databricks.Client.Sample/SampleProgram.Jobs.cs [128:158]


    private static async Task WaitForRun(IJobsApi jobClient, long runId, int pollIntervalSeconds = 15)
    {
        var retryPolicy = Policy.Handle<WebException>()
            .Or<ClientApiException>(e => e.StatusCode == HttpStatusCode.BadGateway)
            .Or<ClientApiException>(e => e.StatusCode == HttpStatusCode.InternalServerError)
            .Or<ClientApiException>(e => e.Message.Contains("\"error_code\":\"TEMPORARILY_UNAVAILABLE\""))
            .Or<TaskCanceledException>(e => !e.CancellationToken.IsCancellationRequested) // web request timeout
            .OrResult<RunState>(state =>
                state.LifeCycleState is RunLifeCycleState.PENDING or RunLifeCycleState.RUNNING
                    or RunLifeCycleState.TERMINATING)
            .WaitAndRetryForeverAsync(
                _ => TimeSpan.FromSeconds(pollIntervalSeconds),
                (delegateResult, _) =>
                {
                    if (delegateResult.Exception != null)
                    {
                        Console.WriteLine(
                            $"[{DateTime.UtcNow:s}] Failed to query run - {delegateResult.Exception}");
                    }
                });

        await retryPolicy.ExecuteAsync(async () =>
        {
            var (run, _) = await jobClient.RunsGet(runId);

            Console.WriteLine(
                $"[{DateTime.UtcNow:s}]Run:{runId}\tLifeCycleState:{run.State.LifeCycleState}\tResultState:{run.State.ResultState}\tCompleted:{run.IsCompleted}"
            );
            return run.State;
        });
    }