add deduplication window
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import decimal
|
||||
import json
|
||||
import math
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import boto3
|
||||
@@ -14,7 +16,7 @@ from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now, ttl
|
||||
from utils import JSONEncoder, diff, table_from_arn
|
||||
from utils import diff, table_from_arn
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from mypy_boto3_events.client import EventBridgeClient
|
||||
@@ -33,7 +35,7 @@ def record_handler(record: DynamoDBRecord):
|
||||
table_name: str = table_from_arn(record.event_source_arn) # type: ignore
|
||||
new_image: dict = record.dynamodb.new_image # type: ignore
|
||||
old_image: dict = record.dynamodb.old_image # type: ignore
|
||||
record_ttl: int = old_image.get('ttl') # type: ignore
|
||||
record_ttl: int | None = old_image.get('ttl')
|
||||
modified = diff(new_image, old_image)
|
||||
now_ = now()
|
||||
|
||||
@@ -63,10 +65,10 @@ def record_handler(record: DynamoDBRecord):
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
logger.info('Event result', result=result)
|
||||
|
||||
|
||||
@logger.inject_lambda_context
|
||||
@tracer.capture_lambda_handler
|
||||
def lambda_handler(event: dict, context: LambdaContext):
|
||||
return process_partial_response(
|
||||
@@ -75,3 +77,20 @@ def lambda_handler(event: dict, context: LambdaContext):
|
||||
processor=processor,
|
||||
context=context,
|
||||
)
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
if o.is_nan():
|
||||
return math.nan
|
||||
|
||||
if o % 1 != 0:
|
||||
return float(o.quantize(decimal.Decimal('0.00')))
|
||||
|
||||
return int(o)
|
||||
|
||||
if isinstance(o, set):
|
||||
return list(o)
|
||||
|
||||
return super().default(o)
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
from typing import Self
|
||||
|
||||
from aws_lambda_powertools.shared.json_encoder import Encoder
|
||||
from aws_lambda_powertools.utilities.data_classes.dynamo_db_stream_event import (
|
||||
DynamoDBRecordEventName,
|
||||
)
|
||||
from meilisearch import Client
|
||||
from utils import JSONEncoder
|
||||
|
||||
|
||||
class JSONEncoder(Encoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, set):
|
||||
return list(obj)
|
||||
|
||||
return super().default(obj)
|
||||
|
||||
|
||||
class Op:
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import decimal
|
||||
import json
|
||||
import math
|
||||
|
||||
import dictdiffer
|
||||
from arnparse import arnparse
|
||||
from aws_lambda_powertools.shared.json_encoder import Encoder
|
||||
|
||||
|
||||
def table_from_arn(arn: str) -> str:
|
||||
@@ -20,8 +23,18 @@ def diff(first: dict, second: dict) -> list[str]:
|
||||
return changed
|
||||
|
||||
|
||||
class JSONEncoder(Encoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, set):
|
||||
return list(obj)
|
||||
return super(__class__, self).default(obj)
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, decimal.Decimal):
|
||||
if o.is_nan():
|
||||
return math.nan
|
||||
|
||||
if o % 1 != 0:
|
||||
return float(o.quantize(decimal.Decimal('0.00')))
|
||||
|
||||
return int(o)
|
||||
|
||||
if isinstance(o, set):
|
||||
return list(o)
|
||||
|
||||
return super().default(o)
|
||||
|
||||
13
streams-events/uv.lock
generated
13
streams-events/uv.lock
generated
@@ -575,7 +575,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "layercake"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
source = { directory = "../layercake" }
|
||||
dependencies = [
|
||||
{ name = "arnparse" },
|
||||
@@ -594,6 +594,7 @@ dependencies = [
|
||||
{ name = "requests" },
|
||||
{ name = "smart-open", extra = ["s3"] },
|
||||
{ name = "sqlite-utils" },
|
||||
{ name = "unidecode" },
|
||||
{ name = "weasyprint" },
|
||||
]
|
||||
|
||||
@@ -615,6 +616,7 @@ requires-dist = [
|
||||
{ name = "requests", specifier = ">=2.32.3" },
|
||||
{ name = "smart-open", extras = ["s3"], specifier = ">=7.1.0" },
|
||||
{ name = "sqlite-utils", specifier = ">=3.38" },
|
||||
{ name = "unidecode", specifier = ">=1.4.0" },
|
||||
{ name = "weasyprint", specifier = ">=65.0" },
|
||||
]
|
||||
|
||||
@@ -1186,6 +1188,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/31/08/aa4fdfb71f7de5176385bd9e90852eaf6b5d622735020ad600f2bab54385/typing_inspection-0.4.0-py3-none-any.whl", hash = "sha256:50e72559fcd2a6367a19f7a7e610e6afcb9fac940c650290eed893d61386832f", size = 14125, upload-time = "2025-02-25T17:27:57.754Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unidecode"
|
||||
version = "1.4.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/94/7d/a8a765761bbc0c836e397a2e48d498305a865b70a8600fd7a942e85dcf63/Unidecode-1.4.0.tar.gz", hash = "sha256:ce35985008338b676573023acc382d62c264f307c8f7963733405add37ea2b23", size = 200149, upload-time = "2025-04-24T08:45:03.798Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/8f/b7/559f59d57d18b44c6d1250d2eeaa676e028b9c527431f5d0736478a73ba1/Unidecode-1.4.0-py3-none-any.whl", hash = "sha256:c3c7606c27503ad8d501270406e345ddb480a7b5f38827eafe4fa82a137f0021", size = 235837, upload-time = "2025-04-24T08:45:01.609Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.3.0"
|
||||
|
||||
Reference in New Issue
Block a user