Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit a2903bc

Browse files
committed
Tracking now behaves better during timeouts
1 parent a23bb12 commit a2903bc

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

data_diff/diff_tables.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414

1515
from .tracking import create_end_event_json, create_start_event_json, send_event_json, is_tracking_enabled
1616
from .sql import Select, Checksum, Compare, Count, TableName, Time, Value
17-
from .utils import CaseAwareMapping, CaseInsensitiveDict, safezip, split_space, CaseSensitiveDict, ArithString
17+
from .utils import (
18+
CaseAwareMapping,
19+
CaseInsensitiveDict,
20+
safezip,
21+
split_space,
22+
CaseSensitiveDict,
23+
ArithString,
24+
run_as_daemon,
25+
)
1826
from .databases.base import Database
1927
from .databases.database_types import (
2028
DbPath,
@@ -334,7 +342,7 @@ def diff_tables(self, table1: TableSegment, table2: TableSegment) -> DiffResult:
334342
if is_tracking_enabled():
335343
options = dict(self)
336344
event_json = create_start_event_json(options)
337-
send_event_json(event_json)
345+
run_as_daemon(send_event_json, event_json)
338346

339347
self.stats["diff_count"] = 0
340348
start = time.monotonic()

data_diff/tracking.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
START_EVENT = "os_diff_run_start"
1717
END_EVENT = "os_diff_run_end"
1818
TOKEN = "ccb8c3a6-3b6f-445c-ad67-994efa7bd020"
19+
TIMEOUT = 8
1920

2021
DEFAULT_PROFILE = os.path.expanduser("~/.datadiff.toml")
2122

@@ -106,7 +107,7 @@ def send_event_json(event_json):
106107
data = json.dumps(event_json).encode()
107108
try:
108109
req = urllib.request.Request(TRACK_URL, data=data, headers=headers)
109-
with urllib.request.urlopen(req) as f:
110+
with urllib.request.urlopen(req, timeout=TIMEOUT) as f:
110111
res = f.read()
111112
if f.code != 200:
112113
raise RuntimeError(res)

data_diff/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from uuid import UUID
88
import operator
99
import string
10+
import threading
1011

1112
alphanums = string.digits + string.ascii_lowercase
1213

@@ -245,3 +246,10 @@ def match_regexps(regexps: Dict[str, Any], s: str) -> Sequence[tuple]:
245246
m = re.match(regexp + "$", s)
246247
if m:
247248
yield m, v
249+
250+
251+
def run_as_daemon(threadfunc, *args):
252+
th = threading.Thread(target=threadfunc, args=args)
253+
th.daemon = True
254+
th.start()
255+
return th

0 commit comments

Comments
 (0)