from notification_service.const import APP_NAME, VERSION from notification_service.db import NotificationDB from notification_service.entities import Config from notification_service.flows.publisher import NotificationPublisher from notification_service.flows.sync_manager import DTFSyncService, SFSyncService from notification_service.message_broker import SNSService, SQSService import boto3 from db_schema.postgres.connection import Connection, aws_credentials_loader from smelog.factory import SmeBoundLogger def handler( logger: SmeBoundLogger, config: Config, ) -> None: try: secretsmanager_client = boto3.client('secretsmanager') pg_main = Connection( credentials_loader=aws_credentials_loader( secretsmanager_client, config.rds_secrets_key ), name=APP_NAME, version=VERSION, ) db = NotificationDB( logger=logger, conn=pg_main, ) dtf_success_msgs, dtf_failed_msgs = DTFSyncService( sqs_service=SQSService(logger=logger, queue=config.dtf_queue_name), db=db, logger=logger, ).run() logger.info( f'[NS] DTF Sync success msgs - {dtf_success_msgs}, failed msgs - {dtf_failed_msgs}' ) sf_success_msgs, sf_failed_msgs = SFSyncService( sqs_service=SQSService(logger=logger, queue=config.sf_queue_name), db=db, logger=logger, ).run() logger.info( f'[NS] SnowFlake Sync success msgs - {sf_success_msgs}, failed msgs - {sf_failed_msgs}' ) logger.info('[NS] Start publishing messages to SNS') NotificationPublisher( db=db, logger=logger, sns_service=SNSService(sns_topic_arn=config.delphi_sns_topic_arn, logger=logger), notification_ttl=config.notification_ttl, thread_counts=config.sns_thread_count ).run() logger.info('[NS] Finish publishing messages to SNS') logger.info('[NS] Start updating of stuck notifications') db.update_stuck_notifications() logger.info('[NS] Finish updating of stuck notifications') logger.info('[NS] Start disable stuck created notifications') db.disable_stuck_created_notifications() logger.info('[NS] Finish disable stuck created notifications') except Exception as exc: logger.exception('[NS] General exception.', exc=exc) raise exc