add fulfillment

This commit is contained in:
2026-01-21 16:13:54 -03:00
parent 2cd000c1cb
commit adcfb420c4
3 changed files with 63 additions and 46 deletions

View File

@@ -10,7 +10,15 @@ from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE
from enrollment import Course, Enrollment, Kind, LinkedEntity, User, enroll
from enrollment import (
Course,
Enrollment,
Kind,
LinkedEntity,
SubscriptionFrozenError,
User,
enroll,
)
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@@ -48,19 +56,25 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
user=user,
)
return enroll(
enrollment,
org=metadata.get('org', None),
subscription=subscription,
# Reuse the deduplication window if it exists
deduplication_window={'offset_days': offset_days} if offset_days else None,
linked_entities=frozenset(
{
LinkedEntity(
id=new_image['id'],
kind=Kind.ENROLLMENT,
),
},
),
persistence_layer=dyn,
)
try:
enroll(
enrollment,
org=metadata.get('org', None),
subscription=subscription,
# Reuse the deduplication window if it exists
deduplication_window={'offset_days': offset_days} if offset_days else None,
# The enrollment must know its source
linked_entities=frozenset(
{
LinkedEntity(
id=new_image['id'],
kind=Kind.ENROLLMENT,
),
},
),
persistence_layer=dyn,
)
except SubscriptionFrozenError:
pass
return True