add fulfillment
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user