enrollment to PF
This commit is contained in:
@@ -29,30 +29,35 @@ enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
course = _get_course(new_image['course']['id'])
|
||||
|
||||
with enrollment_layer.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#deduplication_window',
|
||||
'offset_days': 90,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#course',
|
||||
'created_at': now_,
|
||||
'access_period': int(course['access_period']),
|
||||
'cert': {
|
||||
'exp_interval': int(course['cert']['exp_interval']),
|
||||
},
|
||||
}
|
||||
)
|
||||
try:
|
||||
course = _get_course(new_image['course']['id'])
|
||||
|
||||
return True
|
||||
with enrollment_layer.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#deduplication_window',
|
||||
'offset_days': 90,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#course',
|
||||
'created_at': now_,
|
||||
'access_period': int(course['access_period']),
|
||||
'cert': {
|
||||
'exp_interval': int(course['cert']['exp_interval']),
|
||||
},
|
||||
}
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class CourseNotFoundError(Exception):
|
||||
@@ -50,6 +50,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
flatten_top=False,
|
||||
)
|
||||
|
||||
# If `class_id` is not found, try to retrieve it from the SQLite
|
||||
# migration database.
|
||||
if 'class_id' not in data:
|
||||
data['class_id'] = _get_class_id(course_id)
|
||||
|
||||
@@ -72,6 +74,7 @@ class CourseNotFoundError(Exception):
|
||||
super().__init__('Course not found')
|
||||
|
||||
|
||||
# Post-migration: remove the following function
|
||||
def _get_class_id(course_id: str) -> int:
|
||||
with sqlite3.connect(
|
||||
database=SQLITE_DATABASE, detect_types=sqlite3.PARSE_DECLTYPES
|
||||
@@ -84,4 +87,5 @@ def _get_class_id(course_id: str) -> int:
|
||||
for row in rows:
|
||||
return int(row['json']['metadata__konviva_id'])
|
||||
|
||||
logger.error('Course not found', course_id=course_id)
|
||||
raise CourseNotFoundError
|
||||
|
||||
Reference in New Issue
Block a user