def list()

in src/services/scheduler_service.py [0:0]


    def list(self, name: Optional[str] = None, customer: Optional[str] = None,
             tenants: Optional[Set[str]] = None) -> Iterator[ScheduledJob]:
        tenants = tenants or set()
        if name:
            _LOG.info('Scheduled job name is given querying by it')
            item = self.get(name, customer, tenants)
            return iter([item]) if item else iter([])
        # no name
        if customer and tenants and len(tenants) == 1:
            _LOG.info('Querying by customer using tenant range key '
                      'condition with one tenant')
            return ScheduledJob.customer_name_principal_index.query(
                hash_key=customer,
                range_key_condition=(ScheduledJob.tenant_name == list(tenants)[0])
            )
        if customer:  # and maybe tenants
            # we cannot use IN condition on range keys, but we also cannot use
            # range key for filter conditions. Both cases gave me exceptions.
            # I hate DynamoDB
            _LOG.info('Filtering tenants using python')
            items = ScheduledJob.customer_name_principal_index.query(
                hash_key=customer
            )
            if tenants:
                items = filter(lambda x: x.tenant_name in tenants, items)
            return items
        # no customer
        condition = None
        if tenants:
            condition &= ScheduledJob.tenant_name.is_in(*tenants)
        return ScheduledJob.scan(filter_condition=condition)