def get_failed_products()

in tooling/enrichment/firestore_client.py [0:0]


    def get_failed_products(self):
        """Get list of products that failed and haven't exceeded retry limit."""
        try:
            # First try with a simple status filter
            failed_docs = (
                self.collection
                .where(filter=firestore.FieldFilter('status', '==', 'failed'))
                .stream()
            )
            
            # Filter retry count in memory
            failed_products = []
            for doc in failed_docs:
                data = doc.to_dict()
                retry_count = data.get('retry_count', 0)
                if retry_count < 3:
                    failed_products.append({
                        'id': int(doc.id),
                        **data
                    })
            
            return failed_products
            
        except FailedPrecondition as e:
            print("\nFirestore index error. Please create the following indexes:")
            print("1. Collection: product_index")
            print("2. Fields to index:")
            print("   - status (Ascending)")
            print("   - retry_count (Ascending)")
            print("   - __name__ (Ascending)")
            print("\nYou can create the index using the Firebase Console or using the following command:")
            print("gcloud firestore indexes composite create --collection-group=product_index --field-config field=status,order=ASCENDING field=retry_count,order=ASCENDING field=__name__,order=ASCENDING")
            print("\nOr visit the following URL to create the index:")
            print("https://console.firebase.google.com/project/psearch-dev/firestore/indexes")
            return []