fix test
This commit is contained in:
@@ -7,7 +7,7 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ENROLLMENT_TABLE
|
||||
@@ -22,6 +22,7 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
old_image = event.detail['old_image']
|
||||
sk = old_image['sk']
|
||||
_, lock_hash = sk.split('#')
|
||||
now_ = now()
|
||||
# Key pattern `SCHEDULED#ORG#{org_id}`
|
||||
*_, org_id = old_image['id'].split('#')
|
||||
@@ -57,17 +58,24 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
persistence_layer=dyn,
|
||||
)
|
||||
|
||||
dyn.put_item(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': f'{sk}#EXECUTED',
|
||||
'enrollment_id': enrollment.id,
|
||||
'user': old_image['user'],
|
||||
'course': old_image['course'],
|
||||
'created_by': created_by,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': f'{sk}#EXECUTED',
|
||||
'enrollment_id': enrollment.id,
|
||||
'user': old_image['user'],
|
||||
'course': old_image['course'],
|
||||
'created_by': created_by,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.delete(
|
||||
key=KeyPair(
|
||||
pk='LOCK#SCHEDULED',
|
||||
sk=lock_hash,
|
||||
),
|
||||
)
|
||||
except Exception as exc:
|
||||
dyn.put_item(
|
||||
item={
|
||||
|
||||
Reference in New Issue
Block a user