"""OWS Assets API client.""" import httpx from owsclient import OwsClient from requests import HTTPError from transcoding import config client = OwsClient( config.ENVIRONMENT, config.APP_NAME, retries=config.OWS_RETRIES, timeout=httpx.Timeout(config.OWS_TIMEOUT) ) def post_job_status( transcoding_job_id, status, status_description, metadata=None): """Call ows-transcoding post status handlers. Args: transcoding_job_id (int): Transcoding job id. status (str): Job status. status_description (str): Job status description. metadata (dict): Asset metadata. Optional, defaults to None. """ data = { 'status': status, 'status_description': status_description } if metadata is not None: data['metadata'] = metadata response = client.post( service_name=config.OWS_TRANSCODING_SERVICE_NAME, path=config.POST_JOB_STATUS_PATH_TEMPLATE.format( transcoding_job_id=transcoding_job_id), json=data ) try: response.raise_for_status() except HTTPError as e: error_text = 'Post job status failed with code {status_code}; text {text}'.format( status_code=response.status_code, text=response.text) raise Exception(error_text) from e