remove deduplication as default

This commit is contained in:
2025-10-24 15:15:13 -03:00
parent d45aa1d70e
commit c68aa98fc9
7 changed files with 34 additions and 13 deletions

View File

@@ -13,7 +13,7 @@ EMAIL_SENDER = ('EDUSEG®', 'noreply@eduseg.com.br')
PAPERFORGE_API = 'https://paperforge.saladeaula.digital' PAPERFORGE_API = 'https://paperforge.saladeaula.digital'
CERT_REPORTING_URI = 's3://saladeaula.digital/certs/reporting.html' CERT_REPORTING_URI = 's3://saladeaula.digital/certs/reporting.html'
ESIGN_URI = 's3://saladeaula.digital/esigns/ecnpj_2025.pfx' ESIGN_URI = 's3://saladeaula.digital/esigns/11de2510136adbac.pfx'
DBNAME: str = os.getenv('POSTGRES_DB') # type: ignore DBNAME: str = os.getenv('POSTGRES_DB') # type: ignore

View File

@@ -130,7 +130,7 @@ def enroll(
if deduplication_window if deduplication_window
else DEDUP_WINDOW_OFFSET_DAYS else DEDUP_WINDOW_OFFSET_DAYS
) )
ttl_ = ttl( dedup_lock_ttl = ttl(
start_dt=now_, start_dt=now_,
days=course.access_period - offset_days, days=course.access_period - offset_days,
) )
@@ -140,7 +140,7 @@ def enroll(
'sk': lock_hash, 'sk': lock_hash,
'enrollment_id': enrollment.id, 'enrollment_id': enrollment.id,
'created_at': now_, 'created_at': now_,
'ttl': ttl_, 'ttl': dedup_lock_ttl,
}, },
cond_expr='attribute_not_exists(sk)', cond_expr='attribute_not_exists(sk)',
exc_cls=DeduplicationConflictError, exc_cls=DeduplicationConflictError,
@@ -151,7 +151,7 @@ def enroll(
'sk': 'LOCK', 'sk': 'LOCK',
'hash': lock_hash, 'hash': lock_hash,
'created_at': now_, 'created_at': now_,
'ttl': ttl_, 'ttl': dedup_lock_ttl,
}, },
) )

View File

@@ -52,6 +52,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
enrollment, enrollment,
org=metadata.get('org', None), org=metadata.get('org', None),
subscription=subscription, subscription=subscription,
# Transfer the deduplication window if it exists
deduplication_window={'offset_days': offset_days} if offset_days else None, deduplication_window={'offset_days': offset_days} if offset_days else None,
linked_entities=frozenset( linked_entities=frozenset(
{ {

View File

@@ -1,5 +1,7 @@
import os import os
DEDUP_WINDOW_OFFSET_DAYS = 90
USER_TABLE: str = os.getenv('USER_TABLE') # type: ignore USER_TABLE: str = os.getenv('USER_TABLE') # type: ignore
COURSE_TABLE: str = os.getenv('COURSE_TABLE') # type: ignore COURSE_TABLE: str = os.getenv('COURSE_TABLE') # type: ignore
ENROLLMENT_TABLE: str = os.getenv('ENROLLMENT_TABLE') # type: ignore ENROLLMENT_TABLE: str = os.getenv('ENROLLMENT_TABLE') # type: ignore

View File

@@ -9,7 +9,7 @@ from layercake.dateutils import now, ttl
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
from layercake.strutils import md5_hash from layercake.strutils import md5_hash
from config import COURSE_TABLE from config import COURSE_TABLE, DEDUP_WINDOW_OFFSET_DAYS
logger = Logger(__name__) logger = Logger(__name__)
@@ -117,7 +117,9 @@ def set_score(
) )
user_id = enrollment['user']['id'] user_id = enrollment['user']['id']
course_id = enrollment['course']['id'] course_id = enrollment['course']['id']
dedup_window_offset_days = int(enrollment['dedup_window_offset_days']) dedup_window_offset_days = int(
enrollment.get('dedup_window_offset_days', DEDUP_WINDOW_OFFSET_DAYS)
)
try: try:
if score >= 70: if score >= 70:
@@ -159,7 +161,7 @@ def _set_status_as_completed(
) -> bool: ) -> bool:
now_ = now() now_ = now()
lock_hash = md5_hash(f'{user_id}{course_id}') lock_hash = md5_hash(f'{user_id}{course_id}')
exp_interval = int( cert_exp_interval = int(
dynamodb_persistence_layer.collection.get_item( dynamodb_persistence_layer.collection.get_item(
KeyPair( KeyPair(
pk=course_id, pk=course_id,
@@ -191,17 +193,17 @@ def _set_status_as_completed(
exc_cls=EnrollmentConflictError, exc_cls=EnrollmentConflictError,
) )
if exp_interval: if cert_exp_interval:
dedup_lock_ttl = ttl( dedup_lock_ttl = ttl(
start_dt=now_, start_dt=now_,
days=exp_interval - dedup_window_offset_days, days=cert_exp_interval - dedup_window_offset_days,
) )
transact.put( transact.put(
item={ item={
'id': id, 'id': id,
'sk': 'SCHEDULE#SET_CERT_EXPIRED', 'sk': 'SCHEDULE#SET_CERT_EXPIRED',
'ttl': ttl(start_dt=now_, days=exp_interval), 'ttl': ttl(start_dt=now_, days=cert_exp_interval),
'created_at': now_, 'created_at': now_,
} }
) )
@@ -209,7 +211,7 @@ def _set_status_as_completed(
item={ item={
'id': id, 'id': id,
'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS', 'sk': 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS',
'ttl': ttl(start_dt=now_, days=exp_interval - 30), 'ttl': ttl(start_dt=now_, days=cert_exp_interval - 30),
'created_at': now_, 'created_at': now_,
} }
) )
@@ -231,6 +233,23 @@ def _set_status_as_completed(
'created_at': now_, 'created_at': now_,
} }
) )
else:
transact.put(
item={
'id': id,
'sk': 'LOCK',
'hash': lock_hash,
'created_at': now_,
}
)
transact.put(
item={
'id': 'LOCK',
'sk': lock_hash,
'enrollment_id': id,
'created_at': now_,
}
)
# Remove reminders and policies that no longer apply # Remove reminders and policies that no longer apply
transact.delete( transact.delete(

View File

@@ -20,7 +20,6 @@
{"id": "6c7e3d9b-f5d1-4da4-9e55-0825bb6ff2b8", "sk": "SCHEDULE#SET_ACCESS_EXPIRED"} {"id": "6c7e3d9b-f5d1-4da4-9e55-0825bb6ff2b8", "sk": "SCHEDULE#SET_ACCESS_EXPIRED"}
{"id": "cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae", "sk": "0", "progress": 109, "status": "COMPLETED", "user": {"id": "321", "name": "Chester Bennington"}, "course": {"id": "432", "name": "pytest"}, "created_at": "2022-04-06T11:07:32.762178-03:00"} {"id": "cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae", "sk": "0", "progress": 109, "status": "COMPLETED", "user": {"id": "321", "name": "Chester Bennington"}, "course": {"id": "432", "name": "pytest"}, "created_at": "2022-04-06T11:07:32.762178-03:00"}
{"id": "cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae", "sk": "METADATA#DEDUPLICATION_WINDOW", "offset_days": 90, "created_at": "2025-04-06T11:07:32.762178-03:00"}
{"id": "cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae", "sk": "SCHEDULE#SET_AS_ARCHIVED"} {"id": "cc2c3bce-c34a-4e82-aa6c-1a19e70ec5ae", "sk": "SCHEDULE#SET_AS_ARCHIVED"}
{"id": "5db53b35-0bae-4907-afda-a213cb5bf651", "sk": "0", "progress": 0, "status": "PENDING", "user": {"id": "1234", "name": "Michael Jackinson"}, "course": {"id": "432", "name": "pytest"}, "created_at": "2022-04-06T11:07:32.762178-03:00"} {"id": "5db53b35-0bae-4907-afda-a213cb5bf651", "sk": "0", "progress": 0, "status": "PENDING", "user": {"id": "1234", "name": "Michael Jackinson"}, "course": {"id": "432", "name": "pytest"}, "created_at": "2022-04-06T11:07:32.762178-03:00"}

View File

@@ -113,7 +113,7 @@ def test_set_as_completed(
docx = next((x for x in r['items'] if x['sk'] == '0'), {}) docx = next((x for x in r['items'] if x['sk'] == '0'), {})
assert 'completed_at' in docx assert 'completed_at' in docx
assert len(r['items']) == 6 assert len(r['items']) == 5
assert any(item.get('sk') == 'LOCK' for item in r['items']) assert any(item.get('sk') == 'LOCK' for item in r['items'])
assert any( assert any(
item.get('sk') == 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS' item.get('sk') == 'SCHEDULE#REMINDER_CERT_EXPIRATION_BEFORE_30_DAYS'