import logging from dataclasses import asdict, dataclass import httpx from audience_common.owsclient import OwsClient logger = logging.getLogger(__name__) @dataclass class AudienceDeletedFansReportNotificationArgs: deleted_fans_count: int date: str recipients: list[str] bcc_recipients: list[str] @dataclass class OwsNotificationsClient: ows_client: OwsClient pass_request_context: bool = True service_name = "ows-notifications" def send_fans_deleted_report( self, args: AudienceDeletedFansReportNotificationArgs, ) -> bool: """ Send emails about deleted fans. """ try: response = self.ows_client.post( self.service_name, "/audience/audience-deleted-fans-report", json=asdict(args), ) response.raise_for_status() except httpx.RequestError as exc: logger.error( f"Failed to request `ows-notifications` endpoint: {exc}", extra=asdict(args), exc_info=exc, ) return False try: response.raise_for_status() except httpx.HTTPStatusError as exc: logger.error( "Invalid `ows-notifications` send" f"completed response status: {exc}", extra=asdict(args), exc_info=exc, ) return False return True