def push_dojo_multiple_jobs()

in src/handlers/push_handler.py [0:0]


    def push_dojo_multiple_jobs(self, event: ReportPushMultipleModel):
        tenant = self._modular_client.tenant_service().get(event.tenant_name)
        tenant = modular_helpers.assert_tenant_valid(tenant, event.customer)

        dojo, configuration = next(
            self._integration_service.get_dojo_adapters(tenant), (None, None)
        )
        if not dojo or not configuration:
            raise (
                ResponseFactory(HTTPStatus.BAD_REQUEST)
                .message(
                    f'Tenant {tenant.name} does not have linked dojo configuration'
                )
                .exc()
            )
        client = DojoV2Client(
            url=dojo.url, api_key=self._dds.get_api_key(dojo)
        )

        jobs = self._ambiguous_job_service.get_by_tenant_name(
            tenant_name=tenant.name,
            job_type=event.type,
            status=JobState.SUCCEEDED,
            start=event.start_iso,
            end=event.end_iso,
        )

        tenant_meta = self._rs.fetch_meta(tenant)
        metadata = self._ls.get_customer_metadata(tenant.customer_name)
        responses = []
        platforms = {}  # cache locally platform_id to platform and meta
        for job in self._ambiguous_job_service.to_ambiguous(jobs):
            platform = None
            match job.is_platform_job:
                case True:
                    # A bit of devilish logic because we need to handle both
                    # tenant and platforms in one endpoint. I think it will
                    # be split into two endpoints
                    pid = job.platform_id
                    if pid not in platforms:
                        platform = self._platform_service.get_nullable(pid)
                        meta = {}
                        if platform:
                            meta = self._rs.fetch_meta(platform)
                        platforms[pid] = (
                            self._platform_service.get_nullable(pid),
                            meta,
                        )
                    platform, meta = platforms[pid]
                    if not platform:
                        continue
                    collection = self._rs.platform_job_collection(
                        platform, job.job
                    )
                    collection.meta = meta
                case _:  # only False can be, but underscore for linter
                    collection = self._rs.ambiguous_job_collection(tenant, job)
                    collection.meta = tenant_meta
            collection.fetch_all()

            _configuration = configuration.substitute_fields(
                job=job, platform=platform
            )
            code, message = self._push_dojo(
                client=client,
                configuration=_configuration,
                job=job,
                collection=collection,
                metadata=metadata,
            )
            match code:
                case HTTPStatus.OK:
                    resp = self.get_dojo_dto(
                        job=job, dojo=dojo, configuration=_configuration
                    )
                case _:
                    resp = self.get_dojo_dto(
                        job=job,
                        dojo=dojo,
                        configuration=_configuration,
                        error=message,
                    )
            responses.append(resp)
        return build_response(responses)