reach_commons 0.18.23__tar.gz → 0.18.25__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 (32) hide show
  1. {reach_commons-0.18.23 → reach_commons-0.18.25}/PKG-INFO +1 -1
  2. {reach_commons-0.18.23 → reach_commons-0.18.25}/pyproject.toml +1 -1
  3. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/sqs.py +93 -0
  4. {reach_commons-0.18.23 → reach_commons-0.18.25}/README.md +0 -0
  5. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/__init__.py +0 -0
  6. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/app_logging/__init__.py +0 -0
  7. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/app_logging/http_logger.py +0 -0
  8. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/app_logging/log_deprecated_endpoints.py +0 -0
  9. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/app_logging/logger.py +0 -0
  10. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/app_logging/logging_config.py +0 -0
  11. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/__init__.py +0 -0
  12. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/event_processor.py +0 -0
  13. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/hubspot.py +0 -0
  14. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/outscraper.py +0 -0
  15. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/reach_data_bridge.py +0 -0
  16. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/clients/reach_ops_api.py +0 -0
  17. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/mongo/__init__.py +0 -0
  18. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/mongo/customer_persistence.py +0 -0
  19. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/mongo/customer_persistence_async.py +0 -0
  20. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/mongo/validation/__init__.py +0 -0
  21. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/__init__.py +0 -0
  22. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/commons.py +0 -0
  23. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/dynamo_db.py +0 -0
  24. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/exceptions.py +0 -0
  25. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/firehose.py +0 -0
  26. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/kms.py +0 -0
  27. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_aws/s3.py +0 -0
  28. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/reach_base_model.py +0 -0
  29. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/redis_manager.py +0 -0
  30. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/sms_smart_encoding.py +0 -0
  31. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/utils.py +0 -0
  32. {reach_commons-0.18.23 → reach_commons-0.18.25}/reach_commons/validations.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reach_commons
3
- Version: 0.18.23
3
+ Version: 0.18.25
4
4
  Summary: Reach Commons is a versatile utility library designed to streamline and enhance development workflows within the Reach ecosystem.
5
5
  License: MIT
6
6
  Author: Engineering
@@ -1,7 +1,7 @@
1
1
  # isort .; black .; poetry build; poetry publish
2
2
  [tool.poetry]
3
3
  name = "reach_commons"
4
- version = "0.18.23"
4
+ version = "0.18.25"
5
5
  description = "Reach Commons is a versatile utility library designed to streamline and enhance development workflows within the Reach ecosystem."
6
6
  authors = ["Engineering <engineering@getreach.ai>"]
7
7
  license = "MIT"
@@ -146,6 +146,99 @@ class SQSClient(BaseSQSClient):
146
146
 
147
147
  return True
148
148
 
149
+ def get_visible_messages_count(self) -> int:
150
+ try:
151
+ resp = self.client.get_queue_attributes(
152
+ QueueUrl=self.topic_name,
153
+ AttributeNames=[
154
+ "ApproximateNumberOfMessages",
155
+ "ApproximateNumberOfMessagesNotVisible",
156
+ "ApproximateNumberOfMessagesDelayed",
157
+ ],
158
+ )
159
+ visible = int(resp["Attributes"].get("ApproximateNumberOfMessages", 0))
160
+ in_flight = int(
161
+ resp["Attributes"].get("ApproximateNumberOfMessagesNotVisible", 0)
162
+ )
163
+ delayed = int(
164
+ resp["Attributes"].get("ApproximateNumberOfMessagesDelayed", 0)
165
+ )
166
+
167
+ return visible, in_flight, delayed
168
+ except ClientError as exc:
169
+ self.logger.error(
170
+ "error_fetching_queue_attributes, topic_name=%s, error=%s",
171
+ self.topic_name,
172
+ str(exc),
173
+ )
174
+ # If there's an error, return 0 so as not to block the caller.
175
+ return 0, 0, 0
176
+
177
+ def publish_with_capacity_guard(
178
+ self,
179
+ message_data: dict,
180
+ max_capacity: int,
181
+ delay_seconds: int = 60,
182
+ message_attributes: dict = None,
183
+ ) -> dict:
184
+ """
185
+ Attempts to publish a message while enforcing an approximate queue capacity limit.
186
+
187
+ Behavior:
188
+ - If the queue is below `max_capacity`, the message is published normally.
189
+ - If the queue is at or above `max_capacity`, the message is NOT published.
190
+
191
+ Returns a dict with:
192
+ - posted: bool -> whether the message was actually published
193
+ - visible_count: int -> ApproximateNumberOfMessages at publication time
194
+ - max_capacity: int -> the capacity threshold used
195
+
196
+ Example:
197
+ sqs = SQSClient(topic_name="<enviroment>-messages-queue")
198
+
199
+ Result = sqs.publish_with_capacity_guard(
200
+ message_data={"foo": "bar"},
201
+ max_capacity=100_000,
202
+ delay_seconds=30,
203
+ message_attributes={"service_name": "TestClient"},
204
+ )
205
+
206
+ if not Result["posted"]:
207
+ print("Queue is over capacity:", Result)
208
+ """
209
+ (
210
+ visible_count,
211
+ in_flight_count,
212
+ delayed_count,
213
+ ) = self.get_visible_messages_count()
214
+
215
+ if visible_count >= max_capacity:
216
+ self.logger.warning(
217
+ "queue_over_capacity, topic_name=%s, visible=%s, max_capacity=%s",
218
+ self.topic_name,
219
+ visible_count,
220
+ max_capacity,
221
+ )
222
+ return {
223
+ "posted": False,
224
+ "visible_count": visible_count,
225
+ "max_capacity": max_capacity,
226
+ }
227
+
228
+ self.publish(
229
+ message_data=message_data,
230
+ delay_seconds=delay_seconds,
231
+ message_attributes=message_attributes,
232
+ )
233
+
234
+ return {
235
+ "posted": True,
236
+ "visible_count": visible_count,
237
+ "in_flight_count": in_flight_count,
238
+ "delayed_count": delayed_count,
239
+ "max_capacity": max_capacity,
240
+ }
241
+
149
242
 
150
243
  class MessageFilter:
151
244
  """