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)
|
||||
|
||||
Reference in New Issue
Block a user