Code Monkey home page Code Monkey logo

Comments (3)

aalej avatar aalej commented on August 16, 2024

Hey @skillitzimberg, thanks for reaching out and for providing a detailed report. Let me know if I may have misunderstood anything, but from what I can gather, you are encountering an Error: 9 FAILED_PRECONDITION. error in your scheduled function.

It’s likely that indexes for the query you’re trying to run haven't been generated yet, or are being overwritten by a different one. My guess is that it’s the latter since you mentioned it breaks after deployments.

After deploying the firebase.indexes.json you shared, I tried modifying the code snippet you provided to instead use a descending order and no error were raised:

async function _clearOldDocuments() {
   const date = Date.now() - 600000; // 10 min
   const reports = await admin.firestore()
       .collectionGroup("reports")
       .where("generateDate", "<", new Date(date))
       .orderBy("generateDate", "desc")
       .get();
   for (let doc of reports.docs) {
       console.log(doc.data())
   }
   // const batch = admin.firestore().batch();
   // reports.forEach((d) => batch.delete(d.ref));
   // await batch.commit();
}

Since a descending order worked, I’m guessing the query is using an ascending order. That said, you could either update the query in your code to use a descending order, or modify your indexes to include ascending order like so:

firestore.indexes.json

{
 "indexes": [],
 "fieldOverrides": [
   {
     "collectionGroup": "reports",
     "fieldPath": "generateDate",
     "ttl": false,
     "indexes": [
       {
         "order": "ASCENDING",
         "queryScope": "COLLECTION"
       },
       {
         "order": "DESCENDING",
         "queryScope": "COLLECTION"
       },
       {
         "arrayConfig": "CONTAINS",
         "queryScope": "COLLECTION"
       },
       {
         "order": "DESCENDING",
         "queryScope": "COLLECTION_GROUP"
       },
       {
         "order": "ASCENDING",
         "queryScope": "COLLECTION_GROUP"
       }
     ]
   }
 ]
}

Also you mentioned that hosting deploys break the exemption and scheduled function. Could you elaborate on that? When deploying to hosting are you using firebase deploy --only hosting?

from firebase-tools.

google-oss-bot avatar google-oss-bot commented on August 16, 2024

Hey @skillitzimberg. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

from firebase-tools.

google-oss-bot avatar google-oss-bot commented on August 16, 2024

Since there haven't been any recent updates here, I am going to close this issue.

@skillitzimberg if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

from firebase-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.