def get()

in src/lambdas/custodian_api_handler/handlers/metrics_status_handler.py [0:0]


    def get(self, event: MetricsStatusGetModel):
        from_ = event.start_iso
        to = event.end_iso
        rkc = None
        component_name = self._mc.environment_service().component() or DEFAULT_COMPONENT_NAME

        if from_ and to:
            rkc = Job.started_at.between(from_, to)
        elif from_:
            rkc = Job.started_at >= from_
        elif to:
            rkc = Job.started_at < to
        _LOG.debug(f'Range key condition: {rkc}')

        # TODO api add job_service with corresponding methods
        items = list(
            Job.job_started_at_index.query(
                hash_key=component_name,
                limit=1 if rkc is None else 10,
                range_key_condition=rkc,
                scan_index_forward=False,
            )
        )

        if not items:
            _LOG.warning(
                f'Cannot find metrics update job with component name: '
                f'{component_name}'
            )
        response = []
        for item in items:
            response.append(self.get_metrics_status_dto(item))
        return build_response(content=response)