Skip to content

Commit 750552b

Browse files
committed
fix client timeout
init client at `get_records` level to avoid timout.
1 parent 3bff606 commit 750552b

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

tap_looker/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(self, tap: Tap) -> None:
3030
os.environ["LOOKERSDK_BASE_URL"] = self.config.get("base_url")
3131
os.environ["LOOKERSDK_CLIENT_ID"] = self.config.get("client_id")
3232
os.environ["LOOKERSDK_CLIENT_SECRET"] = self.config.get("client_secret")
33-
self.sdk = looker_sdk.init40()
3433

3534
@property
3635
def schema_filepath(self) -> Path | None:
@@ -80,11 +79,12 @@ def get_records(
8079
Raises:
8180
NotImplementedError: If the implementation is TODO
8281
"""
82+
sdk = looker_sdk.init40()
8383
result_count: int = ROW_LIMIT
8484
result_max_date: datetime = self.get_starting_timestamp(context)
8585
fields = [self.replace_prefix(field) for field in list(self.schema["properties"])]
8686
while result_count == ROW_LIMIT:
87-
response = self.sdk.run_inline_query(
87+
response = sdk.run_inline_query(
8888
result_format="json",
8989
body=models.WriteQuery(
9090
model="system__activity",

tap_looker/streams.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Stream type classes for tap-looker."""
22

33
from __future__ import annotations
4-
import json
54

65
from typing import TYPE_CHECKING
76

7+
import looker_sdk
8+
89
# JSON Schema typing helpers
910
from tap_looker.client import LookerStream, LookerSystemActivityStream
1011

@@ -32,7 +33,8 @@ class ModelStream(LookerStream):
3233

3334
def get_records(self, context: Optional[Context]) -> Iterable[Record]:
3435
"""Return a generator of record-type dictionary objects."""
35-
for model in self.sdk.all_lookml_models():
36+
sdk = looker_sdk.init40()
37+
for model in sdk.all_lookml_models():
3638
if model.name in self.config.get("filter_models", [model.name]):
3739
model_dict = self.convert_to_dict(model)
3840
yield model_dict
@@ -59,8 +61,9 @@ class ExploreStream(LookerStream):
5961

6062
def get_records(self, context: Optional[Context]) -> Iterable[Record]:
6163
"""Return a generator of record-type dictionary objects."""
64+
sdk = looker_sdk.init40()
6265
for explore_name in context["explores"]:
63-
explore = self.sdk.lookml_model_explore(
66+
explore = sdk.lookml_model_explore(
6467
lookml_model_name=context["model_name"],
6568
explore_name=explore_name,
6669
)
@@ -78,8 +81,9 @@ class FieldStream(LookerStream):
7881

7982
def get_records(self, context: Optional[Context]) -> Iterable[Record]:
8083
"""Return a generator of record-type dictionary objects."""
84+
sdk = looker_sdk.init40()
8185
for explore_name in context["explores"]:
82-
explore = self.sdk.lookml_model_explore(
86+
explore = sdk.lookml_model_explore(
8387
lookml_model_name=context["model_name"],
8488
explore_name=explore_name,
8589
)

0 commit comments

Comments
 (0)