"""Module for working with status notifications.""" from src.connectors import ows_assets def _remove_none_entries(source): """Remove entries with None values from dictionary. Args: source (dict): Source dictionary containing entries with None values. Returns: dict: Return a new dictionary with None values filtered out. """ return {key: val for key, val in source.items() if val is not None} def send_general_status( function, status, filename, error_code=None, description=None, bucket=None, input_params=None, result_details=None): """Send general status notification about asset file processing by lambda. Args: function (str): Status source lambda function name. status (str): Status. filename (str): Current processed asset filename. error_code (str): Status error code (for error status). description (str): Status description (if any). bucket (str): Current processed asset source bucket name. input_params (dict): Source lambda additional input params. result_details (dict): Source lambda additional result details. """ if input_params is None: input_params = {} if filename is not None: input_params['key'] = filename if bucket: input_params['bucket'] = bucket message = { 'function': function, 'status': status, 'error_code': error_code, 'description': description, 'input': input_params, 'result': result_details } ows_assets.post_asset_status( filename, status, description or '', _remove_none_entries(message) ) def send_encoding_status(status, key, bucket, status_details='', result_assets=None): """Send encoding status notification about asset file processing by lambda. Args: status (str): Status. key (str): S3 object key. bucket (str): S3 bucket name. status_details (str): Status description. result_assets (list): List of final assets bodies. """ if result_assets is None: result_assets = [] if status_details is None: status_details = '' message = { 'status': status, 'status_details': status_details, 'result_assets': result_assets, 'input': { 'key': key, 'bucket': bucket } } ows_assets.post_asset_final_status( key, status, status_details, result_assets, _remove_none_entries(message) )