add postgres
This commit is contained in:
@@ -32,10 +32,15 @@ def send_email(
|
||||
emailmsg = Message(
|
||||
from_=sender,
|
||||
to=to,
|
||||
subject=subject.format(course=truncate_str(context['course'])),
|
||||
subject=subject.format(
|
||||
course=truncate_str(context['course']),
|
||||
),
|
||||
)
|
||||
emailmsg.add_alternative(
|
||||
message.format(first_name=first_word(name), course=context['course'])
|
||||
message.format(
|
||||
first_name=first_word(name),
|
||||
course=context['course'],
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -46,6 +51,13 @@ def send_email(
|
||||
},
|
||||
}
|
||||
)
|
||||
dynamodb_persistence_layer.put_item(
|
||||
item={
|
||||
'id': event['id'],
|
||||
'sk': f'{event["sk"]}#EXECUTED',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
logger.info('Email sent')
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
@@ -59,13 +71,5 @@ def send_email(
|
||||
)
|
||||
|
||||
return False
|
||||
else:
|
||||
dynamodb_persistence_layer.put_item(
|
||||
item={
|
||||
'id': event['id'],
|
||||
'sk': f'{event["sk"]}#EXECUTED',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
@@ -18,7 +18,7 @@ logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
SUBJECT = 'Seu acesso ao curso de {course} termina em 30 dias'
|
||||
SUBJECT = 'Seu acesso ao curso {course} termina em 30 dias'
|
||||
MESSAGE = """
|
||||
Oi {first_name}, tudo bem?<br/><br/>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
SUBJECT = 'Seu certificado de {course} está prestes a expirar'
|
||||
SUBJECT = 'Seu certificado {course} vai expirar em breve'
|
||||
MESSAGE = """
|
||||
Oi {first_name}, tudo bem?<br/><br/>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
SUBJECT = 'Seu curso de {course} está esperando por você na EDUSEG®'
|
||||
SUBJECT = 'Seu curso {course} está esperando por você na EDUSEG®'
|
||||
MESSAGE = """
|
||||
Oi {first_name}, tudo bem?<br/><br/>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
SUBJECT = 'Seu curso de {course} está parado há 7 dias...'
|
||||
SUBJECT = 'Seu curso {course} está parado há 7 dias...'
|
||||
MESSAGE = """
|
||||
Oi {first_name}, tudo bem?<br><br>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
@@ -21,8 +21,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
enrollment = enrollment_layer.collection.get_items(
|
||||
TransactKey(pk=new_image['id'])
|
||||
+ SortKey('METADATA#DEDUPLICATION_WINDOW', rename_key='DEDUPLICATION_WINDOW')
|
||||
+ SortKey('METADATA#COURSE', rename_key='COURSE'),
|
||||
+ SortKey('METADATA#DEDUPLICATION_WINDOW', rename_key='deduplication_window')
|
||||
+ SortKey('METADATA#COURSE', rename_key='course'),
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@@ -19,16 +19,11 @@ enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
subscription = enrollment_layer.collection.get_items(
|
||||
data = enrollment_layer.collection.get_items(
|
||||
TransactKey(new_image['id'])
|
||||
+ SortKey('METADATA#SUBSCRIPTION_COVERED')
|
||||
+ SortKey('author', rename_key='CREATED_BY')
|
||||
+ SortKey('tenant', rename_key='ORG')
|
||||
+ SortKey('CREATED_BY')
|
||||
+ SortKey('ORG')
|
||||
+ SortKey('METADATA#SUBSCRIPTION_COVERED', rename_key='subscription')
|
||||
+ SortKey('author', rename_key='created_by')
|
||||
+ SortKey('tenant', rename_key='org')
|
||||
)
|
||||
|
||||
with enrollment_layer.transact_writer() as transact_writer:
|
||||
...
|
||||
|
||||
return True
|
||||
|
||||
@@ -37,8 +37,10 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'ttl': ttl(days=3, start_dt=now_),
|
||||
},
|
||||
)
|
||||
|
||||
# By default, the enrollment will expire when the access period ends
|
||||
# (scheduled below).
|
||||
|
||||
# If the enrollment is completed earlier (e.g., certificate issued),
|
||||
# the expiration schedule is canceled and an archive schedule
|
||||
# (`SCHEDULE#SET_AS_ARCHIVED`) is created instead.
|
||||
@@ -53,7 +55,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment_id,
|
||||
'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS',
|
||||
'sk': 'SCHEDULE#REMINDER_ACCESS_PERIOD_BEFORE_30_DAYS',
|
||||
'name': user.name,
|
||||
'email': user.email,
|
||||
'course': course.name,
|
||||
|
||||
@@ -8,11 +8,12 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
from sqlite_utils import Database
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
COURSE_TABLE,
|
||||
ENROLLMENT_TABLE,
|
||||
SQLITE_DATABASE,
|
||||
SQLITE_TABLE,
|
||||
@@ -22,6 +23,7 @@ sqlite3.register_converter('json', json.loads)
|
||||
|
||||
logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
course_layer = DynamoDBPersistenceLayer(COURSE_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
@@ -37,7 +39,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#deduplication_window',
|
||||
'sk': 'METADATA#DEDUPLICATION_WINDOW',
|
||||
'offset_days': 90,
|
||||
'created_at': now_,
|
||||
}
|
||||
@@ -45,7 +47,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'metadata#course',
|
||||
'sk': 'METADATA#COURSE',
|
||||
'created_at': now_,
|
||||
'access_period': int(course['access_period']),
|
||||
'cert': {
|
||||
@@ -66,6 +68,10 @@ class CourseNotFoundError(Exception):
|
||||
|
||||
|
||||
def _get_course(course_id: str) -> dict:
|
||||
course = course_layer.get_item(KeyPair(pk=course_id, sk='0'))
|
||||
if course:
|
||||
return course
|
||||
|
||||
with sqlite3.connect(
|
||||
database=SQLITE_DATABASE, detect_types=sqlite3.PARSE_DECLTYPES
|
||||
) as conn:
|
||||
|
||||
Reference in New Issue
Block a user