This commit is contained in:
2025-07-02 19:50:39 -03:00
parent 0a6db8bc48
commit 8901f44ca3
92 changed files with 158 additions and 11387 deletions

View File

@@ -42,22 +42,27 @@ class LifecycleEvents(str, Enum):
"""Lifecycle events related to scheduling actions."""
# Reminder if the user does not access within 3 days
REMINDER_NO_ACCESS_3_DAYS = 'schedules#reminder_no_access_3_days'
# REMINDER_NO_ACCESS_3_DAYS = 'schedules#reminder_no_access_3_days'
DOES_NOT_ACCESS = 'schedules#does_not_access'
# When there is no activity 7 days after the first access
NO_ACTIVITY_7_DAYS = 'schedules#no_activity_7_days'
# NO_ACTIVITY_7_DAYS = 'schedules#no_activity_7_days'
NO_ACTIVITY = 'schedules#no_activity'
# Reminder 30 days before the access period expires
ACCESS_PERIOD_REMINDER_30_DAYS = 'schedules#access_period_reminder_30_days'
# ACCESS_PERIOD_REMINDER_30_DAYS = 'schedules#access_period_reminder_30_days'
ACCESS_PERIOD_ENDS = 'schedules#access_period_ends'
# Reminder for certificate expiration set to 30 days from now
CERT_EXPIRATION_REMINDER_30_DAYS = 'schedules#cert_expiration_reminder_30_days'
# Archive the course after the certificate expires
COURSE_ARCHIVED = 'schedules#course_archived'
# COURSE_ARCHIVED = 'schedules#course_archived'
ARCHIVE_IT = 'schedules#archive_it'
# When the access period ends for a course without a certificate
COURSE_EXPIRED = 'schedules#course_expired'
# COURSE_EXPIRED = 'schedules#course_expired'
EXPIRATION = 'schedules#expiration'
def enroll(
@@ -106,7 +111,8 @@ def enroll(
transact.put(
item={
'id': enrollment.id,
'sk': LifecycleEvents.REMINDER_NO_ACCESS_3_DAYS,
# 'sk': LifecycleEvents.REMINDER_NO_ACCESS_3_DAYS,
'sk': LifecycleEvents.DOES_NOT_ACCESS,
'name': user.name,
'email': user.email,
'course': course.name,
@@ -120,7 +126,8 @@ def enroll(
transact.put(
item={
'id': enrollment.id,
'sk': LifecycleEvents.COURSE_EXPIRED,
'sk': LifecycleEvents.EXPIRATION,
# 'sk': LifecycleEvents.COURSE_EXPIRED,
'name': user.name,
'email': user.email,
'course': course.name,
@@ -131,7 +138,8 @@ def enroll(
transact.put(
item={
'id': enrollment.id,
'sk': LifecycleEvents.ACCESS_PERIOD_REMINDER_30_DAYS,
# 'sk': LifecycleEvents.ACCESS_PERIOD_REMINDER_30_DAYS,
'sk': LifecycleEvents.ACCESS_PERIOD_ENDS,
'name': user.name,
'email': user.email,
'course': course.name,
@@ -161,14 +169,14 @@ def enroll(
}
)
class VacancyDoesNotExistError(Exception):
class SlotDoesNotExistError(Exception):
def __init__(self, *args):
super().__init__('Vacancy does not exist')
super().__init__('Slot does not exist')
transact.delete(
key=KeyPair(vacancy.id, vacancy.sk),
cond_expr='attribute_exists(sk)',
exc_cls=VacancyDoesNotExistError,
exc_cls=SlotDoesNotExistError,
)
transact.put(
item={
@@ -277,10 +285,10 @@ def set_status_as_canceled(
cond_expr='attribute_exists(sk)',
)
# Remove schedules lifecycle events, referencies and locks
transact.delete(key=KeyPair(id, 'schedules#archive_it'))
transact.delete(key=KeyPair(id, 'schedules#no_activity'))
transact.delete(key=KeyPair(id, 'schedules#access_period_ends'))
transact.delete(key=KeyPair(id, 'schedules#does_not_access'))
transact.delete(key=KeyPair(id, LifecycleEvents.ARCHIVE_IT))
transact.delete(key=KeyPair(id, LifecycleEvents.NO_ACTIVITY))
transact.delete(key=KeyPair(id, LifecycleEvents.ACCESS_PERIOD_ENDS))
transact.delete(key=KeyPair(id, LifecycleEvents.DOES_NOT_ACCESS))
transact.delete(key=KeyPair(id, 'parent_vacancy'))
transact.delete(key=KeyPair(id, 'lock'))
transact.delete(key=KeyPair('lock', lock_hash))
@@ -305,8 +313,9 @@ def set_status_as_canceled(
},
cond_expr='attribute_not_exists(sk)',
)
# Post-migration: rename `generated_items` to `slots`.
# Set the status of `generated_items` to `ROLLBACK` to know
# which vacancy is available for reuse
# which slot is available for reuse
transact.update(
key=KeyPair(order_id, f'generated_items#{enrollment_id}'),
update_expr='SET #status = :status, update_date = :update',

View File

@@ -26,7 +26,7 @@ Globals:
Architectures:
- x86_64
Layers:
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:75
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:79
Environment:
Variables:
TZ: America/Sao_Paulo
@@ -37,7 +37,6 @@ Globals:
USER_TABLE: !Ref UserTable
ORDER_TABLE: !Ref OrderTable
ENROLLMENT_TABLE: !Ref EnrollmentTable
NEW_ENROLLMENT_TABLE: !Ref NewEnrollmentTable
COURSE_TABLE: !Ref CourseTable
ELASTIC_CLOUD_ID: "{{resolve:ssm:/betaeducacao/elastic/cloud_id/str}}"
ELASTIC_AUTH_PASS: "{{resolve:ssm:/betaeducacao/elastic/auth_pass/str}}"