Skip to content

Commit

Permalink
1745 Revise logging for the VA Profile opt-in/out lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbfled committed May 14, 2024
1 parent 2815fec commit 8ae007a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lambda_functions/va_profile/va_profile_opt_in_out_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


logger = logging.getLogger('VAProfileOptInOut')
logger.setLevel(logging.DEBUG)
logger.setLevel(getattr(logging, os.getenv('LOG_LEVEL', 'DEBUG')))

ALB_CERTIFICATE_ARN = os.getenv('ALB_CERTIFICATE_ARN')
ALB_PRIVATE_KEY_PATH = os.getenv('ALB_PRIVATE_KEY_PATH')
Expand Down Expand Up @@ -297,12 +297,19 @@ def va_profile_opt_in_out_lambda_handler( # noqa: C901
return post_response

try:
params = ( # Stored function parameters:
bio['vaProfileId'], # _va_profile_id
bio['communicationItemId'], # _communication_item_id
bio['communicationChannelId'], # _communication_channel_name
bio['allowed'], # _allowed
bio['sourceDate'], # _source_datetime
# Stored function parameters:
params = (
bio['vaProfileId'], # _va_profile_id
bio['communicationItemId'], # _communication_item_id
bio['communicationChannelId'], # _communication_channel_name
bio['allowed'], # _allowed
bio['sourceDate'], # _source_datetime
)

logger.info(
'Opting-%s for VA Profile ID %s',
'in' if (str(bio['allowed']).lower() == 'true') else 'out',
bio['vaProfileId'],
)

global db_connection
Expand All @@ -314,13 +321,12 @@ def va_profile_opt_in_out_lambda_handler( # noqa: C901
if db_connection is None:
raise RuntimeError('No database connection.')

logger.debug('Executing the stored function . . .')
with db_connection.cursor() as c:
# https://www.psycopg.org/docs/cursor.html#cursor.execute
c.execute(OPT_IN_OUT_QUERY, params)
put_body['status'] = 'COMPLETED_SUCCESS' if c.fetchone()[0] else 'COMPLETED_NOOP'
db_connection.commit()
logger.debug('. . . Executed the stored function.')
logger.debug('Executed the stored function.')
except KeyError as e:
# Bad Request. Required attributes are missing.
post_response['statusCode'] = 400
Expand Down

0 comments on commit 8ae007a

Please sign in to comment.