fix bug
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
from os import access
|
||||
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.utilities.data_classes import (
|
||||
EventBridgeEvent,
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from glom import glom
|
||||
from layercake.dateutils import now, ttl
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
@@ -20,10 +23,18 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
enrollment_id = new_image['id']
|
||||
user = new_image['user']
|
||||
course = new_image['course']
|
||||
now_ = now()
|
||||
course_name = glom(new_image, 'course.name')
|
||||
access_period = int(
|
||||
dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=enrollment_id,
|
||||
sk=SortKey('METADATA#COURSE', path_spec='access_period'),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.put(
|
||||
@@ -32,7 +43,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'sk': 'SCHEDULE#REMINDER_NO_ACCESS_AFTER_3_DAYS',
|
||||
'name': user['name'],
|
||||
'email': user['email'],
|
||||
'course': course['name'],
|
||||
'course': course_name,
|
||||
'created_at': now_,
|
||||
'ttl': ttl(days=3, start_dt=now_),
|
||||
},
|
||||
@@ -49,18 +60,19 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'id': enrollment_id,
|
||||
'sk': 'SCHEDULE#SET_AS_EXPIRED',
|
||||
'created_at': now_,
|
||||
'ttl': ttl(start_dt=now_, days=course.access_period),
|
||||
'ttl': ttl(start_dt=now_, days=access_period),
|
||||
},
|
||||
)
|
||||
print(access_period)
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment_id,
|
||||
'sk': 'SCHEDULE#REMINDER_ACCESS_PERIOD_BEFORE_30_DAYS',
|
||||
'name': user['name'],
|
||||
'email': user['email'],
|
||||
'course': course['name'],
|
||||
'course': course_name,
|
||||
'created_at': now_,
|
||||
'ttl': ttl(start_dt=now_, days=course.access_period - 30),
|
||||
'ttl': ttl(start_dt=now_, days=access_period - 30),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user