Skip to content
Back

While loop in a function throws error

  • 0
  • Functions
dhatGuy
14 May, 2024, 22:55

I have a function that loops through documents to check to check their expiredDate . It results to error when I run the function triggered by a cron job.

TypeScript
An internal curl error has occurred within the executor! Error Number: 104. Error Msg: Connection reset by peer\nError Code: 500

It runs fine when I remove the while loop. Here's the code

TypeScript
      while (products.total > 0) {
        for (const product of products.documents) {
          if (new Date(product.expiryDate) < new Date()) {
            await db.createDocument("drug-inventory", "notification", ID.unique(), {
              type: "expired-drug",
              isAdmin: false,
              product: product.$id,
              expiredDate: product.expiryDate,
            });
          }
        }
        offset += 50;
        products = await db.listDocuments("drug-inventory", "products", [
          Query.limit(50),
          Query.offset(offset),
        ]);
        }
TL;DR
A developer's function with a while loop checking for expired dates in documents triggers a curl error when run by a cron job. The error message is `An internal curl error has occurred within the executor! Error Number: 104. Error Msg: Connection reset by peer\nError Code: 500`. The loop runs smoothly without the while loop.
Steven
14 May, 2024, 22:56

How long does it run before this happens?

dhatGuy
14 May, 2024, 22:57

1 - 3 seconds

Steven
14 May, 2024, 22:58

And it happens every time?

dhatGuy
14 May, 2024, 22:59

yes, everytime

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more