import logging from dataclasses import asdict, dataclass import httpx from owsclient import OwsClient logger = logging.getLogger(__name__) @dataclass class ShopifyStoreSyncCompletedNotificationArgs: identity_id: str store_id: str store_domain: str is_multiartist_store: bool @dataclass class AdReportingSyncCompletedNotificationArgs: identity_id: str ad_accounts: list[str] ad_reporting_platform: str @dataclass class OwsNotificationsClient: ows_client: OwsClient service_name = "ows-notifications" def notify_shopify_store_sync_completed( self, args: ShopifyStoreSyncCompletedNotificationArgs, ) -> bool: """ Sends request to ows-notifications service to notify user about shopify store sync completion. Returns True in success case otherwise returns False. """ try: response = self.ows_client.post( self.service_name, "/audience/shopify-store-sync-completed", json=asdict(args), ) response.raise_for_status() except httpx.RequestError as exc: logger.error( "Failed to request `ows-notifications` endpoint", extra=asdict(args), exc_info=exc, ) return False try: response.raise_for_status() except httpx.HTTPStatusError as exc: logger.error( "Invalid `ows-notifications` Shopify store sync " "completed response status", extra=asdict(args), exc_info=exc, ) return False return True def notify_ad_reporting_sync_completed( self, args: AdReportingSyncCompletedNotificationArgs, ) -> bool: """ Sends request to ows-notifications service to notify user about ad reporting data sync completion. Returns True in success case otherwise returns False. """ try: response = self.ows_client.post( self.service_name, "/audience/ad-reporting-sync-completed", json=asdict(args), ) response.raise_for_status() except httpx.RequestError as exc: logger.error( "Failed to request `ows-notifications` endpoint", extra=asdict(args), exc_info=exc, ) return False try: response.raise_for_status() except httpx.HTTPStatusError as exc: logger.error( "Invalid `ows-notifications` Shopify store sync " "completed response status", extra=asdict(args), exc_info=exc, ) return False return True