events-sdk-python 0.0.3__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/PKG-INFO +3 -2
  2. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/events_sdk_python.egg-info/PKG-INFO +3 -2
  3. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/consumer.py +7 -6
  4. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/request.py +4 -0
  5. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/consumer.py +79 -0
  6. events_sdk_python-0.0.5/hightouch/htevents/version.py +1 -0
  7. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/pyproject.toml +1 -1
  8. events-sdk-python-0.0.3/hightouch/htevents/version.py +0 -1
  9. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/LICENSE +0 -0
  10. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/README.md +0 -0
  11. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/events_sdk_python.egg-info/SOURCES.txt +0 -0
  12. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/events_sdk_python.egg-info/dependency_links.txt +0 -0
  13. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/events_sdk_python.egg-info/requires.txt +0 -0
  14. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/events_sdk_python.egg-info/top_level.txt +0 -0
  15. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/__init__.py +0 -0
  16. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/client.py +0 -0
  17. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/oauth_manager.py +0 -0
  18. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/__init__.py +0 -0
  19. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/client.py +0 -0
  20. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/constants.py +0 -0
  21. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/module.py +0 -0
  22. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/oauth.py +0 -0
  23. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/request.py +0 -0
  24. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/test/utils.py +0 -0
  25. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/hightouch/htevents/utils.py +0 -0
  26. {events-sdk-python-0.0.3 → events_sdk_python-0.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: events-sdk-python
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: Events SDK Python for Hightouch event collection.
5
5
  Author-email: Hightouch <engineering@hightouch.com>
6
6
  License: MIT License
@@ -72,6 +72,7 @@ Requires-Dist: pyjwt[crypto]
72
72
  Provides-Extra: dev
73
73
  Requires-Dist: mock==2.0.0; extra == "dev"
74
74
  Requires-Dist: ruff==0.1.4; extra == "dev"
75
+ Dynamic: license-file
75
76
 
76
77
  # Events SDK Python
77
78
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: events-sdk-python
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: Events SDK Python for Hightouch event collection.
5
5
  Author-email: Hightouch <engineering@hightouch.com>
6
6
  License: MIT License
@@ -72,6 +72,7 @@ Requires-Dist: pyjwt[crypto]
72
72
  Provides-Extra: dev
73
73
  Requires-Dist: mock==2.0.0; extra == "dev"
74
74
  Requires-Dist: ruff==0.1.4; extra == "dev"
75
+ Dynamic: license-file
75
76
 
76
77
  # Events SDK Python
77
78
 
@@ -90,12 +90,16 @@ class Consumer(Thread):
90
90
  self.log.error('error uploading: %s', e)
91
91
  success = False
92
92
  if self.on_error:
93
- self.on_error(e, batch)
93
+ try:
94
+ self.on_error(e, batch)
95
+ except Exception:
96
+ # A raising callback must not kill the consumer thread.
97
+ self.log.exception('error in on_error callback')
94
98
  finally:
95
99
  # mark items as acknowledged from queue
96
100
  for _ in batch:
97
101
  self.queue.task_done()
98
- return success
102
+ return success
99
103
 
100
104
  def next(self):
101
105
  """Return the next batch of items to upload."""
@@ -132,10 +136,7 @@ class Consumer(Thread):
132
136
 
133
137
  def fatal_exception(exc):
134
138
  if isinstance(exc, APIError):
135
- # retry on server errors and client errors
136
- # with 429 status code (rate limited),
137
- # don't retry on other client errors
138
- return (400 <= exc.status < 500) and exc.status != 429
139
+ return 400 <= exc.status < 500 and exc.status not in (408, 429)
139
140
  elif isinstance(exc, FatalError):
140
141
  return True
141
142
  else:
@@ -83,6 +83,10 @@ def post(
83
83
  payload = res.json()
84
84
  log.debug('received response: %s', payload)
85
85
  raise APIError(res.status_code, payload['code'], payload['message'])
86
+ except (KeyError, TypeError):
87
+ if res.status_code in (408, 429) or 500 <= res.status_code < 600:
88
+ raise APIError(res.status_code, 'unknown', res.text)
89
+ raise
86
90
  except ValueError:
87
91
  log.error('Unknown error: [%s] %s', res.status_code, res.reason)
88
92
  raise APIError(res.status_code, 'unknown', res.text)
@@ -49,6 +49,83 @@ class TestConsumer(unittest.TestCase):
49
49
  success = consumer.upload()
50
50
  self.assertTrue(success)
51
51
 
52
+ def test_upload_failure_returns_false_and_acks_queue(self):
53
+ q = Queue()
54
+ consumer = Consumer(q, TEST_WRITE_KEY)
55
+ track = {'type': 'track', 'event': 'python event', 'userId': 'userId'}
56
+ q.put(track)
57
+ with mock.patch.object(
58
+ consumer, 'request', side_effect=Exception('upload failed')
59
+ ):
60
+ success = consumer.upload()
61
+ self.assertFalse(success)
62
+ self.assertTrue(q.empty())
63
+ q.join()
64
+
65
+ def test_on_error_called_on_upload_failure(self):
66
+ q = Queue()
67
+ errors = []
68
+
69
+ def on_error(error, batch):
70
+ errors.append((error, batch))
71
+
72
+ consumer = Consumer(q, TEST_WRITE_KEY, on_error=on_error)
73
+ track = {'type': 'track', 'event': 'python event', 'userId': 'userId'}
74
+ q.put(track)
75
+ upload_error = Exception('upload failed')
76
+ with mock.patch.object(consumer, 'request', side_effect=upload_error):
77
+ success = consumer.upload()
78
+ self.assertFalse(success)
79
+ self.assertEqual(len(errors), 1)
80
+ self.assertIs(errors[0][0], upload_error)
81
+ self.assertEqual(errors[0][1], [track])
82
+ q.join()
83
+
84
+ def test_on_error_exception_does_not_propagate(self):
85
+ q = Queue()
86
+
87
+ def on_error(error, batch):
88
+ raise RuntimeError('callback failed')
89
+
90
+ consumer = Consumer(q, TEST_WRITE_KEY, on_error=on_error)
91
+ track = {'type': 'track', 'event': 'python event', 'userId': 'userId'}
92
+ q.put(track)
93
+ with mock.patch.object(
94
+ consumer, 'request', side_effect=Exception('upload failed')
95
+ ):
96
+ # Capture logs so the intentional traceback is not emitted to
97
+ # stderr (GitHub Actions would annotate it as a check failure).
98
+ with self.assertLogs('hightouch', level='ERROR') as logs:
99
+ success = consumer.upload()
100
+ self.assertFalse(success)
101
+ self.assertTrue(q.empty())
102
+ q.join()
103
+ self.assertTrue(
104
+ any('error in on_error callback' in message for message in logs.output)
105
+ )
106
+
107
+ def test_on_error_exception_does_not_stop_consumer(self):
108
+ q = Queue()
109
+
110
+ def on_error(error, batch):
111
+ raise RuntimeError('callback failed')
112
+
113
+ consumer = Consumer(
114
+ q, TEST_WRITE_KEY, on_error=on_error, retries=0, upload_interval=0.1
115
+ )
116
+ with mock.patch(
117
+ 'hightouch.htevents.consumer.post', side_effect=Exception('upload failed')
118
+ ):
119
+ with self.assertLogs('hightouch', level='ERROR'):
120
+ consumer.start()
121
+ q.put({'type': 'track', 'event': 'e1', 'userId': 'userId'})
122
+ q.join()
123
+ q.put({'type': 'track', 'event': 'e2', 'userId': 'userId'})
124
+ q.join()
125
+ self.assertTrue(consumer.is_alive())
126
+ consumer.pause()
127
+ consumer.join(timeout=2)
128
+
52
129
  def test_upload_interval(self):
53
130
  # Put _n_ items in the queue, pausing a little bit more than
54
131
  # _upload_interval_ after each one.
@@ -138,6 +215,8 @@ class TestConsumer(unittest.TestCase):
138
215
  consumer, APIError(500, 'code', 'Internal Server Error'), 2
139
216
  )
140
217
 
218
+ self._test_request_retry(consumer, APIError(408, 'code', 'Request Timeout'), 1)
219
+
141
220
  # we should retry on HTTP 429 errors
142
221
  consumer = Consumer(None, TEST_WRITE_KEY)
143
222
  self._test_request_retry(
@@ -0,0 +1 @@
1
+ VERSION = '0.0.5'
@@ -8,7 +8,7 @@ include = ["hightouch*"]
8
8
 
9
9
  [project]
10
10
  name = "events-sdk-python"
11
- version = "0.0.3"
11
+ version = "0.0.5"
12
12
  description = "Events SDK Python for Hightouch event collection."
13
13
  readme = "README.md"
14
14
  authors = [{ name = "Hightouch", email = "engineering@hightouch.com" }]
@@ -1 +0,0 @@
1
- VERSION = '0.0.3'