Skip to content

Commit 8bcd956

Browse files
committed
removed constants
1 parent e124135 commit 8bcd956

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lambdas/ack_backend/src/audit_table.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,20 @@ def set_records_succeeded_count(message_id: str) -> None:
6262
records_failed = int(records_failed_item) if records_failed_item else 0
6363
records_succeeded = record_count - records_failed
6464

65-
attribute_name = AuditTableKeys.RECORDS_SUCCEEDED
6665
try:
6766
response = dynamodb_client.update_item(
6867
TableName=AUDIT_TABLE_NAME,
6968
Key={AuditTableKeys.MESSAGE_ID: {"S": message_id}},
7069
UpdateExpression="SET #attribute = :value",
71-
ExpressionAttributeNames={"#attribute": attribute_name},
70+
ExpressionAttributeNames={"#attribute": AuditTableKeys.RECORDS_SUCCEEDED},
7271
ExpressionAttributeValues={":value": {"N": str(records_succeeded)}},
7372
ConditionExpression=CONDITION_EXPRESSION,
7473
ReturnValues="UPDATED_NEW",
7574
)
76-
result = response.get("Attributes", {}).get(attribute_name).get("N")
75+
result = response.get("Attributes", {}).get(AuditTableKeys.RECORDS_SUCCEEDED).get("N")
7776
logger.info(
7877
"Attribute %s for message id %s set to %s in the audit table",
79-
attribute_name,
78+
AuditTableKeys.RECORDS_SUCCEEDED,
8079
message_id,
8180
result,
8281
)
@@ -94,19 +93,17 @@ def increment_records_failed_count(message_id: str) -> None:
9493

9594
increment_value = 1
9695
initial_value = 0
97-
attribute_name = AuditTableKeys.RECORDS_FAILED
9896
try:
9997
# Use SET with if_not_exists to safely increment the counter attribute
100-
response = dynamodb_client.update_item(
98+
dynamodb_client.update_item(
10199
TableName=AUDIT_TABLE_NAME,
102100
Key={AuditTableKeys.MESSAGE_ID: {"S": message_id}},
103101
UpdateExpression="SET #attribute = if_not_exists(#attribute, :initial) + :increment",
104-
ExpressionAttributeNames={"#attribute": attribute_name},
102+
ExpressionAttributeNames={"#attribute": AuditTableKeys.RECORDS_FAILED},
105103
ExpressionAttributeValues={":increment": {"N": str(increment_value)}, ":initial": {"N": str(initial_value)}},
106104
ConditionExpression=CONDITION_EXPRESSION,
107105
ReturnValues="UPDATED_NEW",
108106
)
109-
response.get("Attributes", {}).get(attribute_name).get("N")
110107

111108
except Exception as error: # pylint: disable = broad-exception-caught
112109
logger.error(error)

0 commit comments

Comments
 (0)