internal async Task <SFBaseResultSet> ExecuteAsync(int timeout, string sql, Dictionary <string, BindingDTO> bindings, bool describeOnly, CancellationToken cancellationToken) { registerQueryCancellationCallback(timeout, cancellationToken); var queryRequest = BuildQueryRequest(sql, bindings, describeOnly); try { QueryExecResponse response = null; bool receivedFirstQueryResponse = false; while (!receivedFirstQueryResponse) { response = await _restRequester.PostAsync <QueryExecResponse>(queryRequest, cancellationToken).ConfigureAwait(false); if (SessionExpired(response)) { SfSession.renewSession(); queryRequest.authorizationToken = string.Format(SF_AUTHORIZATION_SNOWFLAKE_FMT, SfSession.sessionToken); } else { receivedFirstQueryResponse = true; } } var lastResultUrl = response.data?.getResultUrl; while (RequestInProgress(response) || SessionExpired(response)) { var req = BuildResultRequest(lastResultUrl); response = await _restRequester.GetAsync <QueryExecResponse>(req, cancellationToken).ConfigureAwait(false); if (SessionExpired(response)) { logger.Info("Ping pong request failed with session expired, trying to renew the session."); SfSession.renewSession(); } else { lastResultUrl = response.data?.getResultUrl; } } return(BuildResultSet(response, cancellationToken)); } catch { logger.Error("Query execution failed."); throw; } finally { ClearQueryRequestId(); } }
internal async Task <SFBaseResultSet> ExecuteAsync(int timeout, string sql, Dictionary <string, BindingDTO> bindings, bool describeOnly, CancellationToken cancellationToken) { registerQueryCancellationCallback(timeout, cancellationToken); var queryRequest = BuildQueryRequest(sql, bindings, describeOnly); try { var response = await _restRequester.PostAsync <QueryExecResponse>(queryRequest, cancellationToken); if (SessionExpired(response)) { SfSession.renewSession(); ClearQueryRequestId(); return(await ExecuteAsync(timeout, sql, bindings, describeOnly, cancellationToken)); } var lastResultUrl = response.data?.getResultUrl; while (RequestInProgress(response) || SessionExpired(response)) { var req = BuildResultRequest(lastResultUrl); response = await _restRequester.GetAsync <QueryExecResponse>(req, cancellationToken); if (SessionExpired(response)) { logger.Info("Ping pong request failed with session expired, trying to renew the session."); SfSession.renewSession(); } else { lastResultUrl = response.data?.getResultUrl; } } return(BuildResultSet(response, cancellationToken)); } catch (Exception ex) { logger.Error("Query execution failed.", ex); throw; } finally { ClearQueryRequestId(); } }