fix duplicate user
This commit is contained in:
@@ -14,8 +14,6 @@ from boto3clients import dynamodb_client
|
||||
from config import ENROLLMENT_TABLE, ORDER_TABLE
|
||||
from enrollment import (
|
||||
Enrollment,
|
||||
Kind,
|
||||
LinkedEntity,
|
||||
Seat,
|
||||
Subscription,
|
||||
enroll,
|
||||
@@ -54,21 +52,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
)
|
||||
|
||||
try:
|
||||
# The enrollment must know its source
|
||||
linked_entities = (
|
||||
frozenset(
|
||||
{
|
||||
LinkedEntity(
|
||||
id=seat['order_id'],
|
||||
kind=Kind.ORDER,
|
||||
table_name=ORDER_TABLE,
|
||||
),
|
||||
},
|
||||
)
|
||||
if seat
|
||||
else frozenset()
|
||||
)
|
||||
|
||||
enroll(
|
||||
enrollment,
|
||||
org={
|
||||
@@ -82,7 +65,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
scheduled_at=datetime.fromisoformat(old_image['scheduled_at']),
|
||||
# Transfer the deduplication window if it exists
|
||||
deduplication_window={'offset_days': offset_days} if offset_days else None,
|
||||
linked_entities=linked_entities,
|
||||
persistence_layer=dyn,
|
||||
)
|
||||
|
||||
@@ -105,17 +87,49 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
),
|
||||
)
|
||||
except Exception as exc:
|
||||
dyn.put_item(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': f'{sk}#FAILED',
|
||||
'cause': {
|
||||
'type': type(exc).__name__,
|
||||
'message': str(exc),
|
||||
},
|
||||
'snapshot': old_image,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': f'{sk}#FAILED',
|
||||
'cause': {
|
||||
'type': type(exc).__name__,
|
||||
'message': str(exc),
|
||||
},
|
||||
'snapshot': old_image,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
if seat:
|
||||
order_id = seat['order_id']
|
||||
transact.update(
|
||||
key=KeyPair(
|
||||
pk=order_id,
|
||||
sk=f'ENROLLMENT#{enrollment.id}',
|
||||
),
|
||||
cond_expr='attribute_exists(sk) AND #status = :scheduled',
|
||||
update_expr='SET #status = :rollback, \
|
||||
rollback_at = :now, \
|
||||
reason = :reason',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
expr_attr_values={
|
||||
':rollback': 'ROLLBACK',
|
||||
':scheduled': 'SCHEDULED',
|
||||
':reason': 'DEDUPLICATION',
|
||||
':now': now_,
|
||||
},
|
||||
table_name=ORDER_TABLE,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': f'SEAT#ORG#{org_id}',
|
||||
'sk': f'ORDER#{order_id}#ENROLLMENT#{uuid4()}',
|
||||
'course': enrollment.course.model_dump(),
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user