"""An interface to ows-charts microservice.""" from oto import response from owsrequest import request from . import config OWS_CHARTS_ERROR = 'OWS_CHARTS_ERROR' def prime_chart_dates(chart_dates): """Request cache invalidation and priming for a selection of chart dates. Args: chart_dates (list): A list of chart_id and chart_date pairs. Returns: oto.Response: a response containing an ok message or an error """ ows_charts_response = request.process( application=config.feed_name, environment=config.environment, method='POST', service_name='ows-charts', path='/charts/prime', json={ 'chart_dates': chart_dates, } ) if ows_charts_response.status_code == 200: return response.Response(ows_charts_response.json()) try: response_errors = ows_charts_response.json() except (TypeError, ValueError): response_errors = ows_charts_response.content.decode('utf-8') return response.create_error_response( code=OWS_CHARTS_ERROR, message=response_errors, status=ows_charts_response.status_code, )