diff --git a/konviva-events/app/app.py b/konviva-events/app/app.py index 22f2902..04a4ce1 100644 --- a/konviva-events/app/app.py +++ b/konviva-events/app/app.py @@ -23,7 +23,7 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client) @app.post('/') @tracer.capture_method -def update_enrollment(): +def postback(): json_body = app.current_event.json_body status = json_body['status'] diff --git a/konviva-events/app/enrollment.py b/konviva-events/app/enrollment.py index bcdeb82..b701a49 100644 --- a/konviva-events/app/enrollment.py +++ b/konviva-events/app/enrollment.py @@ -65,6 +65,7 @@ def update_progress( ':progress': progress, ':updated_at': now_, }, + exc_cls=EnrollmentConflictError, ) # Record the start date if it does not already exist transact.put( @@ -140,7 +141,9 @@ def set_score( user_id=user_id, course_id=course_id, cert_exp_interval=int( - glom(enrollment, 'metadata__course.cert.exp_interval') + glom( + enrollment, 'metadata__course.cert.exp_interval', default=0 + ) ), dedup_window_offset_days=int( enrollment['dedup_window_offset_days'] @@ -216,39 +219,42 @@ def _set_status_as_completed( }, cond_expr='attribute_not_exists(sk)', ) - transact.put( - item={ - 'id': id, - 'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS', - 'ttl': cert_expiration_reminder_ttl, - 'created_at': now_, - } - ) - transact.put( - item={ - 'id': id, - 'sk': 'SCHEDULE#SET_AS_ARCHIVED', - 'ttl': archive_ttl, - 'created_at': now_, - } - ) - transact.put( - item={ - 'id': id, - 'sk': 'LOCK', - 'ttl': deduplication_lock_ttl, - 'created_at': now_, - } - ) - transact.put( - item={ - 'id': 'LOCK', - 'sk': lock_hash, - 'enrollment_id': id, - 'ttl': deduplication_lock_ttl, - 'created_at': now_, - } - ) + + if cert_exp_interval: + transact.put( + item={ + 'id': id, + 'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS', + 'ttl': cert_expiration_reminder_ttl, + 'created_at': now_, + } + ) + transact.put( + item={ + 'id': id, + 'sk': 'SCHEDULE#SET_AS_ARCHIVED', + 'ttl': archive_ttl, + 'created_at': now_, + } + ) + transact.put( + item={ + 'id': id, + 'sk': 'LOCK', + 'ttl': deduplication_lock_ttl, + 'created_at': now_, + } + ) + transact.put( + item={ + 'id': 'LOCK', + 'sk': lock_hash, + 'enrollment_id': id, + 'ttl': deduplication_lock_ttl, + 'created_at': now_, + } + ) + # Remove reminders and policies that no longer apply transact.delete( key=KeyPair( @@ -420,4 +426,6 @@ class EnrollmentNotFoundError(NotFoundError): super().__init__('Enrollment not found') -class EnrollmentConflictError(BadRequestError): ... +class EnrollmentConflictError(BadRequestError): + def __init__(self, *_): + super().__init__('Enrollment conflict')