Skip to content

Commit c4e6cef

Browse files
committed
add heartbeat interval
Signed-off-by: Ben Cassell <[email protected]>
1 parent 5636b8f commit c4e6cef

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/databricks/sql/thrift_backend.py

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
TIMESTAMP_AS_STRING_CONFIG = "spark.thriftserver.arrowBasedRowSet.timestampAsString"
5757
DEFAULT_SOCKET_TIMEOUT = float(900)
58+
DEFAULT_STATEMENT_HEARTBEAT_INTERVAL = float(25)
5859

5960
# see Connection.__init__ for parameter descriptions.
6061
# - Min/Max avoids unsustainable configs (sane values are far more constrained)
@@ -77,6 +78,7 @@ class ThriftBackend:
7778
_retry_stop_after_attempts_count: int
7879
_retry_stop_after_attempts_duration: float
7980
_retry_delay_default: float
81+
_statement_heartbeat_interval: float
8082

8183
def __init__(
8284
self,
@@ -134,6 +136,10 @@ def __init__(
134136
# An integer representing the maximum number of redirects to follow for a request.
135137
# This number must be <= _retry_stop_after_attempts_count.
136138
# (defaults to None)
139+
# _statement_heartbeat_interval
140+
# The number of seconds to wait between sending GetOperationStatus requests to the server.
141+
# (defaults to 25), as the server will already wait 5 seconds before responding to the request if the
142+
# statement is still running, making a 30 second total interval between each heartbeat.
137143
# max_download_threads
138144
# Number of threads for handling cloud fetch downloads. Defaults to 10
139145

@@ -231,6 +237,10 @@ def __init__(
231237
# setTimeout defaults to 15 minutes and is expected in ms
232238
self._transport.setTimeout(timeout and (float(timeout) * 1000.0))
233239

240+
self._statement_heartbeat_interval = kwargs.get(
241+
"_statement_heartbeat_interval", DEFAULT_STATEMENT_HEARTBEAT_INTERVAL
242+
)
243+
234244
self._transport.setCustomHeaders(dict(http_headers))
235245
protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocol(self._transport)
236246
self._client = TCLIService.Client(protocol)
@@ -802,6 +812,7 @@ def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
802812
ttypes.TOperationState.RUNNING_STATE,
803813
ttypes.TOperationState.PENDING_STATE,
804814
]:
815+
time.sleep(self._statement_heartbeat_interval)
805816
poll_resp = self._poll_for_status(op_handle)
806817
operation_state = poll_resp.operationState
807818
self._check_command_not_in_error_or_closed_state(op_handle, poll_resp)

0 commit comments

Comments
 (0)