add event

This commit is contained in:
2025-07-05 15:02:28 -03:00
parent 208c43f398
commit 0df4d7aa71
9 changed files with 96 additions and 51 deletions

View File

@@ -8,7 +8,6 @@ from layercake.dynamodb import (
ComposeKey,
DynamoDBPersistenceLayer,
KeyPair,
SortKey,
)
from boto3clients import dynamodb_client
@@ -29,27 +28,19 @@ class TenantDoesNotExistError(Exception):
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
new_image = event.detail['new_image']
order_id = new_image['id']
# Post-migration: remove the following line
tenant_id = order_layer.collection.get_item(
KeyPair(
order_id,
SortKey('metadata#tenant', path_spec='tenant_id'),
),
exc_cls=TenantDoesNotExistError,
).removeprefix('ORG#')
# Post-migration: uncomment the following line
# tenant_id = new_image['tenant']
tenant_id = new_image['tenant']
result = enrollment_layer.collection.query(
KeyPair(
# Post-migration: uncomment the following line
# ComposeKey(tenant_id, prefix='slots'),
# ComposeKey(tenant_id, prefix='slots#org'),
ComposeKey(tenant_id, prefix='vacancies'),
order_id,
)
)
logger.info('Slots found', slots=result['items'])
with enrollment_layer.batch_writer() as batch:
for pair in result['items']:
batch.delete_item(