update events
This commit is contained in:
@@ -64,13 +64,13 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
|
||||
return order_layer.update_item(
|
||||
key=KeyPair(new_image['id'], new_image['sk']),
|
||||
update_expr='SET #status = :status, updated_at = :updated_at',
|
||||
update_expr='SET #status = :status, updated_at = :now',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
expr_attr_values={
|
||||
':status': 'SUCCESS',
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ def send_email(
|
||||
) -> bool:
|
||||
now_ = now()
|
||||
name, _ = to
|
||||
event_name = event['sk']
|
||||
emailmsg = Message(
|
||||
from_=sender,
|
||||
to=to,
|
||||
@@ -54,7 +55,7 @@ def send_email(
|
||||
dynamodb_persistence_layer.put_item(
|
||||
item={
|
||||
'id': event['id'],
|
||||
'sk': f'{event["sk"]}#EXECUTED',
|
||||
'sk': f'{event_name}#EXECUTED',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
@@ -65,7 +66,7 @@ def send_email(
|
||||
dynamodb_persistence_layer.put_item(
|
||||
item={
|
||||
'id': event['id'],
|
||||
'sk': f'{event["sk"]}#FAILED',
|
||||
'sk': f'{event_name}#FAILED',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -62,7 +62,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
},
|
||||
) as fp:
|
||||
result = fp.process()
|
||||
logger.info('Processed courses', result=result)
|
||||
logger.debug('Processed courses', result=result)
|
||||
|
||||
return order_layer.update_item(
|
||||
key=KeyPair(new_image['id'], new_image['sk']),
|
||||
|
||||
@@ -33,6 +33,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
)
|
||||
|
||||
if 'cert' not in course:
|
||||
logger.debug('Certificate not found')
|
||||
# There is no certificate to issue from metadata
|
||||
return False
|
||||
|
||||
@@ -73,7 +74,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
logger.exception(exc)
|
||||
raise
|
||||
|
||||
logger.info(f'PDF uploaded successfully to {s3_uri}')
|
||||
logger.debug(f'PDF uploaded successfully to {s3_uri}')
|
||||
|
||||
return enrollment_layer.update_item(
|
||||
key=KeyPair(
|
||||
|
||||
@@ -39,8 +39,12 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
)
|
||||
user = User.model_validate(new_image['user'])
|
||||
course = Course.model_validate(new_image['course'] | metadata['course'])
|
||||
enrollment = Enrollment(id=uuid4(), course=course, user=user)
|
||||
subscription = metadata['subscription'] if 'subscription' in metadata else None
|
||||
enrollment = Enrollment(
|
||||
id=uuid4(),
|
||||
course=course,
|
||||
user=user,
|
||||
)
|
||||
|
||||
return enroll(
|
||||
enrollment,
|
||||
|
||||
@@ -27,6 +27,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
enrollment_id = new_image['id']
|
||||
user = new_image['user']
|
||||
course_name = glom(new_image, 'course.name')
|
||||
# Post-migration: after removing the stopgap file `patch_course_metadata.py`,
|
||||
# use `access_expires_at` from `new_image`
|
||||
access_period = int(
|
||||
dyn.collection.get_item(
|
||||
KeyPair(
|
||||
@@ -49,20 +51,16 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
},
|
||||
)
|
||||
|
||||
# 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.
|
||||
# Schedule the event to add `access_expired` after the access period ends
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment_id,
|
||||
'sk': 'SCHEDULE#SET_AS_EXPIRED',
|
||||
'sk': 'SCHEDULE#SET_ACCESS_EXPIRED',
|
||||
'created_at': now_,
|
||||
'ttl': ttl(start_dt=now_, days=access_period),
|
||||
},
|
||||
)
|
||||
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment_id,
|
||||
|
||||
@@ -19,8 +19,6 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
"""If there is no certificate and the access period has ended,
|
||||
the enrollment will be marked as expired."""
|
||||
old_image = event.detail['old_image']
|
||||
now_ = now()
|
||||
|
||||
@@ -31,30 +29,17 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
pk=old_image['id'],
|
||||
sk='0',
|
||||
),
|
||||
update_expr='SET #status = :expired, updated_at = :updated_at',
|
||||
cond_expr='#status = :in_progress OR #status = :pending',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
update_expr='SET access_expired = :true, \
|
||||
updated_at = :now',
|
||||
expr_attr_values={
|
||||
':pending': 'PENDING',
|
||||
':in_progress': 'IN_PROGRESS',
|
||||
':expired': 'EXPIRED',
|
||||
':updated_at': now_,
|
||||
':true': True,
|
||||
':now': now_,
|
||||
},
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'EXPIRED',
|
||||
'expired_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'SCHEDULE#SET_AS_EXPIRED#EXECUTED',
|
||||
'sk': 'SCHEDULE#SET_ACCESS_EXPIRED#EXECUTED',
|
||||
'created_at': now_,
|
||||
},
|
||||
)
|
||||
@@ -64,7 +49,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
dyn.put_item(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'SCHEDULE#SET_AS_EXPIRED#FAILED',
|
||||
'sk': 'SCHEDULE#SET_ACCESS_EXPIRED#FAILED',
|
||||
'reason': str(exc),
|
||||
'created_at': now_,
|
||||
},
|
||||
@@ -5,7 +5,7 @@ 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, KeyPair
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
@@ -19,9 +19,16 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
"""After the certificate expires, the enrollment will be marked as archived."""
|
||||
old_image = event.detail['old_image']
|
||||
now_ = now()
|
||||
issued_cert = dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=old_image['id'],
|
||||
sk=SortKey('0', path_spec='issued_cert'),
|
||||
),
|
||||
raise_on_error=False,
|
||||
default={},
|
||||
)
|
||||
|
||||
try:
|
||||
with dyn.transact_writer() as transact:
|
||||
@@ -30,29 +37,20 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
pk=old_image['id'],
|
||||
sk='0',
|
||||
),
|
||||
update_expr='SET #status = :archived, updated_at = :updated_at',
|
||||
update_expr='SET issued_cert = :issued_cert, \
|
||||
updated_at = :now',
|
||||
cond_expr='#status = :completed',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
},
|
||||
expr_attr_names={'#status': 'status'},
|
||||
expr_attr_values={
|
||||
':issued_cert': issued_cert | {'expired': True},
|
||||
':completed': 'COMPLETED',
|
||||
':archived': 'ARCHIVED',
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'ARCHIVED',
|
||||
'archived_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'SCHEDULE#SET_AS_ARCHIVED#EXECUTED',
|
||||
'sk': 'SCHEDULE#SET_CERT_EXPIRED#EXECUTED',
|
||||
'created_at': now_,
|
||||
},
|
||||
)
|
||||
@@ -62,7 +60,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
dyn.put_item(
|
||||
item={
|
||||
'id': old_image['id'],
|
||||
'sk': 'SCHEDULE#SET_AS_ARCHIVED#FAILED',
|
||||
'sk': 'SCHEDULE#SET_CERT_EXPIRED#FAILED',
|
||||
'reason': str(exc),
|
||||
'created_at': now_,
|
||||
},
|
||||
@@ -37,10 +37,10 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.update(
|
||||
key=KeyPair(new_image['id'], '0'),
|
||||
update_expr='SET subscription_covered = :subscription_covered, \
|
||||
updated_at = :updated_at',
|
||||
updated_at = :now',
|
||||
expr_attr_values={
|
||||
':subscription_covered': True,
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
)
|
||||
|
||||
@@ -307,12 +307,10 @@ Resources:
|
||||
keys:
|
||||
sk: [SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS]
|
||||
|
||||
# If there is no certificate and the access period has ended,
|
||||
# the enrollment will be marked as expired
|
||||
EventSetAsExpiredFunction:
|
||||
EventSetAccessExpiredFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.set_as_expired.lambda_handler
|
||||
Handler: events.set_access_expired.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
@@ -327,13 +325,12 @@ Resources:
|
||||
detail-type: [EXPIRE]
|
||||
detail:
|
||||
keys:
|
||||
sk: [SCHEDULE#SET_AS_EXPIRED]
|
||||
sk: [SCHEDULE#SET_ACCESS_EXPIRED, SCHEDULE#SET_AS_EXPIRED]
|
||||
|
||||
# After the certificate expires, the enrollment will be marked as archived
|
||||
EventSetAsArchivedFunction:
|
||||
EventSetCertExpiredFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: events.set_as_archived.lambda_handler
|
||||
Handler: events.set_cert_expired.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref EventLog
|
||||
Policies:
|
||||
@@ -348,7 +345,7 @@ Resources:
|
||||
detail-type: [EXPIRE]
|
||||
detail:
|
||||
keys:
|
||||
sk: [SCHEDULE#SET_AS_ARCHIVED]
|
||||
sk: [SCHEDULE#SET_CERT_EXPIRED, SCHEDULE#SET_AS_ARCHIVED]
|
||||
|
||||
EventScheduleRemindersFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import app.events.set_as_archived as app
|
||||
import app.events.set_access_expired as app
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBPersistenceLayer,
|
||||
@@ -7,7 +7,7 @@ from layercake.dynamodb import (
|
||||
)
|
||||
|
||||
|
||||
def test_set_as_archived(
|
||||
def test_set_access_expired(
|
||||
seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
@@ -15,7 +15,7 @@ def test_set_as_archived(
|
||||
event = {
|
||||
'detail': {
|
||||
'old_image': {
|
||||
'id': '845fe390-e3c3-4514-97f8-c42de0566cf0',
|
||||
'id': '6437a282-6fe8-4e4d-9eb0-da1007238007',
|
||||
'sk': '0',
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,10 @@ def test_set_as_archived(
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
|
||||
r = dynamodb_persistence_layer.collection.get_items(
|
||||
TransactKey('845fe390-e3c3-4514-97f8-c42de0566cf0')
|
||||
TransactKey('6437a282-6fe8-4e4d-9eb0-da1007238007')
|
||||
+ SortKey('0')
|
||||
+ SortKey('SCHEDULE#SET_AS_ARCHIVED#EXECUTED', rename_key='executed')
|
||||
+ SortKey('SCHEDULE#SET_ACCESS_EXPIRED#EXECUTED', rename_key='executed')
|
||||
)
|
||||
assert r['status'] == 'ARCHIVED'
|
||||
assert r['status'] == 'IN_PROGRESS'
|
||||
assert 'executed' in r
|
||||
assert 'access_expired' in r
|
||||
@@ -1,4 +1,4 @@
|
||||
import app.events.set_as_expired as app
|
||||
import app.events.set_cert_expired as app
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBPersistenceLayer,
|
||||
@@ -7,31 +7,7 @@ from layercake.dynamodb import (
|
||||
)
|
||||
|
||||
|
||||
def test_set_as_expired(
|
||||
seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
event = {
|
||||
'detail': {
|
||||
'old_image': {
|
||||
'id': '6437a282-6fe8-4e4d-9eb0-da1007238007',
|
||||
'sk': '0',
|
||||
}
|
||||
}
|
||||
}
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
|
||||
r = dynamodb_persistence_layer.collection.get_items(
|
||||
TransactKey('6437a282-6fe8-4e4d-9eb0-da1007238007')
|
||||
+ SortKey('0')
|
||||
+ SortKey('SCHEDULE#SET_AS_EXPIRED#EXECUTED', rename_key='executed')
|
||||
)
|
||||
assert r['status'] == 'EXPIRED'
|
||||
assert 'executed' in r
|
||||
|
||||
|
||||
def test_set_as_expired_failed(
|
||||
def test_set_cert_expired(
|
||||
seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
@@ -44,12 +20,34 @@ def test_set_as_expired_failed(
|
||||
}
|
||||
}
|
||||
}
|
||||
assert not app.lambda_handler(event, lambda_context) # type: ignore
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
|
||||
r = dynamodb_persistence_layer.collection.get_items(
|
||||
TransactKey('845fe390-e3c3-4514-97f8-c42de0566cf0')
|
||||
+ SortKey('0')
|
||||
+ SortKey('SCHEDULE#SET_AS_EXPIRED#FAILED', rename_key='failed')
|
||||
+ SortKey('SCHEDULE#SET_CERT_EXPIRED#EXECUTED', rename_key='executed')
|
||||
)
|
||||
assert r['status'] == 'COMPLETED'
|
||||
assert 'failed' in r
|
||||
assert 'executed' in r
|
||||
assert 'issued_cert' in r
|
||||
|
||||
|
||||
def test_existing_issued_cert(
|
||||
seeds,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
event = {
|
||||
'detail': {
|
||||
'old_image': {
|
||||
'id': '1ee108ae-67d4-4545-bf6d-4e641cdaa4e0',
|
||||
'sk': '0',
|
||||
}
|
||||
}
|
||||
}
|
||||
assert app.lambda_handler(event, lambda_context) # type: ignore
|
||||
|
||||
r = dynamodb_persistence_layer.collection.get_items(
|
||||
TransactKey('1ee108ae-67d4-4545-bf6d-4e641cdaa4e0') + SortKey('0')
|
||||
)
|
||||
assert 's3_uri' in r['issued_cert']
|
||||
@@ -24,7 +24,7 @@
|
||||
{"id": "845fe390-e3c3-4514-97f8-c42de0566cf0", "sk": "0", "status": "COMPLETED", "progress": 100}
|
||||
{"id": "14682b79-3df2-4351-9229-8b558af046a0", "sk": "METADATA#COURSE", "access_period": 360}
|
||||
|
||||
{"id": "1ee108ae-67d4-4545-bf6d-4e641cdaa4e0", "sk": "0", "score": 100, "course": {"name": "CIPA Grau de Risco 1"}, "user": {"name": "Kurt Cobain"}}
|
||||
{"id": "1ee108ae-67d4-4545-bf6d-4e641cdaa4e0", "sk": "0", "status": "COMPLETED", "score": 100, "course": {"name": "CIPA Grau de Risco 1"}, "user": {"name": "Kurt Cobain"}, "issued_cert": {"s3_uri": "s3://saladeaula.digital/issuedcerts/1ee108ae-67d4-4545-bf6d-4e641cdaa4e0.pdf"}}
|
||||
{"id": "1ee108ae-67d4-4545-bf6d-4e641cdaa4e0", "sk": "METADATA#COURSE", "cert": {"s3_uri": "s3://saladeaula.digital/certs/samples/cipa-grau-de-risco-1.html", "exp_interval": 700}}
|
||||
{"id": "1ee108ae-67d4-4545-bf6d-4e641cdaa4e0", "sk": "STARTED", "started_at": "2025-08-24T01:44:42.703012-03:06"}
|
||||
{"id": "1ee108ae-67d4-4545-bf6d-4e641cdaa4e0", "sk": "COMPLETED", "completed_at": "2025-08-31T21:59:10.842467-03:00"}
|
||||
|
||||
@@ -25,7 +25,8 @@ def update_progress(
|
||||
# Update progress only if the enrollment status is `IN_PROGRESS`
|
||||
transact.update(
|
||||
key=KeyPair(id, '0'),
|
||||
update_expr='SET progress = :progress, updated_at = :updated_at',
|
||||
update_expr='SET progress = :progress, \
|
||||
updated_at = :now',
|
||||
cond_expr='#status = :in_progress',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
@@ -33,7 +34,7 @@ def update_progress(
|
||||
expr_attr_values={
|
||||
':in_progress': 'IN_PROGRESS',
|
||||
':progress': progress,
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
exc_cls=EnrollmentConflictError,
|
||||
)
|
||||
@@ -49,11 +50,12 @@ def update_progress(
|
||||
except EnrollmentConflictError:
|
||||
with dynamodb_persistence_layer.transact_writer() as transact:
|
||||
# If the enrollment status is `PENDING`, set it to `IN_PROGRESS`
|
||||
# and update progress and updated_at date
|
||||
# and update `progress` and `updated_at`
|
||||
transact.update(
|
||||
key=KeyPair(id, '0'),
|
||||
update_expr='SET progress = :progress, #status = :in_progress, \
|
||||
updated_at = :updated_at',
|
||||
update_expr='SET progress = :progress, \
|
||||
#status = :in_progress, \
|
||||
updated_at = :now',
|
||||
cond_expr='#status = :pending',
|
||||
expr_attr_names={
|
||||
'#status': 'status',
|
||||
@@ -62,7 +64,7 @@ def update_progress(
|
||||
':in_progress': 'IN_PROGRESS',
|
||||
':pending': 'PENDING',
|
||||
':progress': progress,
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
exc_cls=EnrollmentConflictError,
|
||||
)
|
||||
@@ -189,15 +191,15 @@ def _set_status_as_completed(
|
||||
update_expr='SET #status = :completed, \
|
||||
progress = :progress, \
|
||||
score = :score, \
|
||||
updated_at = :updated_at',
|
||||
updated_at = :now',
|
||||
cond_expr='#status = :in_progress',
|
||||
expr_attr_names={'#status': 'status'},
|
||||
expr_attr_values={
|
||||
':completed': 'COMPLETED',
|
||||
':in_progress': 'IN_PROGRESS',
|
||||
':score': score,
|
||||
':updated_at': now_,
|
||||
':progress': progress,
|
||||
':now': now_,
|
||||
},
|
||||
exc_cls=EnrollmentConflictError,
|
||||
)
|
||||
@@ -214,7 +216,7 @@ def _set_status_as_completed(
|
||||
transact.put(
|
||||
item={
|
||||
'id': id,
|
||||
'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS',
|
||||
'sk': 'SCHEDULE#SET_CERT_EXPIRED',
|
||||
'ttl': cert_exp_ttl,
|
||||
'created_at': now_,
|
||||
}
|
||||
@@ -222,7 +224,7 @@ def _set_status_as_completed(
|
||||
transact.put(
|
||||
item={
|
||||
'id': id,
|
||||
'sk': 'SCHEDULE#SET_CERT_EXPIRED',
|
||||
'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS',
|
||||
'ttl': cert_exp_reminder_ttl,
|
||||
'created_at': now_,
|
||||
}
|
||||
@@ -288,8 +290,8 @@ def _set_status_as_failed(
|
||||
update_expr='SET #status = :failed, \
|
||||
progress = :progress, \
|
||||
score = :score, \
|
||||
access_expired = :access_expired, \
|
||||
updated_at = :updated_at',
|
||||
access_expired = :true, \
|
||||
updated_at = :now',
|
||||
cond_expr='#status = :in_progress',
|
||||
expr_attr_names={'#status': 'status'},
|
||||
expr_attr_values={
|
||||
@@ -297,8 +299,8 @@ def _set_status_as_failed(
|
||||
':in_progress': 'IN_PROGRESS',
|
||||
':score': score,
|
||||
':progress': progress,
|
||||
':access_expired': True,
|
||||
':updated_at': now_,
|
||||
':true': True,
|
||||
':now': now_,
|
||||
},
|
||||
exc_cls=EnrollmentConflictError,
|
||||
)
|
||||
|
||||
@@ -18,10 +18,12 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@logger.inject_lambda_context
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
data = dyn.get_item(KeyPair(new_image['id'], 'konviva'))
|
||||
r = dyn.get_item(KeyPair(new_image['id'], 'konviva'))
|
||||
# Post-migration: uncomment the following line
|
||||
# r = dyn.get_item(KeyPair(new_image['id'], 'KONVIVA'))
|
||||
|
||||
try:
|
||||
result = konviva.cancel_enrollment(data['enrollment_id'])
|
||||
result = konviva.cancel_enrollment(r['enrollment_id'])
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
return False
|
||||
|
||||
@@ -47,10 +47,10 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.update(
|
||||
key=KeyPair(new_image['id'], '0'),
|
||||
update_expr='SET metadata__konviva_user_id = :user_id, \
|
||||
updated_at = :updated_at',
|
||||
updated_at = :now',
|
||||
expr_attr_values={
|
||||
':user_id': user_id,
|
||||
':updated_at': now_,
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
)
|
||||
|
||||
@@ -35,6 +35,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.update(
|
||||
key=KeyPair(new_image['id'], 'konviva'),
|
||||
# Post-migration: uncomment the following line
|
||||
# key=KeyPair(new_image['id'], 'KONVIVA'),
|
||||
update_expr='SET enrollment_id = :enrollment_id',
|
||||
cond_expr='attribute_exists(sk)',
|
||||
expr_attr_values={
|
||||
@@ -45,6 +47,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'konviva',
|
||||
# Post-migration: uncomment the following line
|
||||
# 'id': 'KONVIVA',
|
||||
'sk': str(enrollment_id),
|
||||
'enrollment_id': new_image['id'],
|
||||
'created_at': now_,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import pprint
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from layercake.dateutils import now
|
||||
@@ -159,65 +158,3 @@ def test_set_as_failed(
|
||||
PartitionKey('6c7e3d9b-f5d1-4da4-9e55-0825bb6ff2b8')
|
||||
)
|
||||
assert any(item.get('sk') == 'FAILED' for item in r['items'])
|
||||
|
||||
|
||||
# def test_set_as_archived(
|
||||
# app,
|
||||
# seeds,
|
||||
# dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
# http_api_proxy: HttpApiProxy,
|
||||
# lambda_context: LambdaContext,
|
||||
# ):
|
||||
# # This data was added from seeds
|
||||
# r = app.lambda_handler(
|
||||
# http_api_proxy(
|
||||
# raw_path='/',
|
||||
# method=HTTPMethod.POST,
|
||||
# body={
|
||||
# 'ID_MATRICULA': '899',
|
||||
# 'APROVEITAMENTO': '70',
|
||||
# 'ANDAMENTO': '100',
|
||||
# 'status': 'COMPLETED',
|
||||
# },
|
||||
# ),
|
||||
# lambda_context,
|
||||
# )
|
||||
# assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
||||
|
||||
# # Check `seeds.jsonl` for sample data related to this query
|
||||
# r = dynamodb_persistence_layer.collection.query(
|
||||
# PartitionKey('cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae')
|
||||
# )
|
||||
# assert any(item.get('sk') == 'ARCHIVED' for item in r['items'])
|
||||
# assert len(r['items']) == 4
|
||||
|
||||
|
||||
# def test_set_as_expired(
|
||||
# app,
|
||||
# seeds,
|
||||
# dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
# http_api_proxy: HttpApiProxy,
|
||||
# lambda_context: LambdaContext,
|
||||
# ):
|
||||
# # This data was added from seeds
|
||||
# r = app.lambda_handler(
|
||||
# http_api_proxy(
|
||||
# raw_path='/',
|
||||
# method=HTTPMethod.POST,
|
||||
# body={
|
||||
# 'ID_MATRICULA': '221',
|
||||
# 'APROVEITAMENTO': '69',
|
||||
# 'ANDAMENTO': '100',
|
||||
# 'status': 'COMPLETED',
|
||||
# },
|
||||
# ),
|
||||
# lambda_context,
|
||||
# )
|
||||
# assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
||||
|
||||
# # Check `seeds.jsonl` for sample data related to this query
|
||||
# r = dynamodb_persistence_layer.collection.query(
|
||||
# PartitionKey('5db53b35-0bae-4907-afda-a213cb5bf651')
|
||||
# )
|
||||
# assert any(item.get('sk') == 'EXPIRED' for item in r['items'])
|
||||
# assert len(r['items']) == 3
|
||||
|
||||
Reference in New Issue
Block a user