""" This module contains functions to set track contributions (participants, performers, and publishers) for a single track. """ import json from connectors.logging import log from utils.concurrency_utils import prepare_errors_dict from logic.graphql_logic import set_track_contributions from config import REPORT_FAILED_PAYLOADS def task_set_track_contributions( tuid: str, vendor_id: str, subaccount_id: str, participations: list, performers: list = None, publishers: list = None, task_id: int = None): """" For a single TUID, sets or creates participants (as needed), sets performers, and/or publishers from lists of dicts, with a label ID string, and executes a GQL mutation to set track performers, participants, and publishers. Args: tuid (str): The track unique identifier. vendor_id (str): The label ID. subaccount_id (str): The subaccount ID. participations (list): A list of dictionaries containing participant data. performers (list) (optional): A list of dictionaries containing performer data. publishers (list) (optional): A list of dictionaries containing publisher data. task_id (str) (optional): The task ID if called from a multi-threaded process. Returns: tuple (dict, dict): The updated track data and the errors. """ # Future: 1. creation functions to format performers & participant dicts # and translate string values to IDs from the bulk ingester template # 2. can fetch Participant UUID from name within this function """ def format_performers(performers): # {'name': 'Ted Franklin', 'roleId': '20'} # return as list of dicts pass def format_publishers(performers): # {'name': 'Wilson Cheong LLC 2005'} # return as list of dicts pass def format_participants(participants): # {'role': 'COMPOSER', 'labelParticipantUuid': '1234-5678-9012'} # return as list of dicts pass """ errors = None msg = f'Updating track participations for {tuid} on {vendor_id}' msg = task_id and f'Task {task_id}: {msg}' or msg log.debug(msg) # Set track contributions track_data, error_dict = set_track_contributions( tuid, vendor_id, subaccount_id, participations, performers, publishers, task_id ) if not track_data: # Log error msg = f'Error setting track contributions for {tuid} on vendor ' \ f'{vendor_id}' if task_id: msg = f'Task {task_id}: {msg}' log.error(msg) error = { 'tuid': tuid, 'vendor_id': vendor_id, 'subaccount_id': subaccount_id, 'error': error_dict, 'message': msg, 'task_id': task_id, 'calling_func': 'task_set_track_contributions()' } # Prepare error dict errors = prepare_errors_dict({}, 'tuid', tuid) errors['track'][tuid].append(error) if errors: # If the payload is not empty, print it to the log if REPORT_FAILED_PAYLOADS and error.get('payload'): # Notify user of offending payload msg = f'Offending payload:\n' \ f"{json.dumps(error['payload'], indent=4)}" if task_id: msg = f'Task {task_id}: {msg}' log.error(msg) track_data = {} return track_data, errors