Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📚 Documentation: Updating Document via Cloud Function runs with Event [document.update] in loop #3025

Closed
2 tasks done
anandsubbu007 opened this issue Mar 27, 2022 · 6 comments
Assignees

Comments

@anandsubbu007
Copy link

💭 Description

when i try to alter the data which is created or updated via event trigger.
it runs in loop.

how to prevent it from running in loop

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@anandsubbu007 anandsubbu007 changed the title 📚 Documentation: Updating Document via Cloud Function runs in loop 📚 Documentation: Updating Document via Cloud Function runs with Event [document.update] in loop Mar 27, 2022
@Meldiron
Copy link
Contributor

I can imagine there are multiple ways to prevent it. What I have seen people doing in the community is to have updatedAt attribute on the document, and update it each time a function updates the document.

To prevent the loop, in the function you can check how big a difference between updatedAt and the current time is. If it is something smaller than 1 second, it means the loop is starting, and in such a case, simply stop the execution. This way 2 executions are created, but the second is stopped as soon as it realises it's creating a loop.

@Meldiron Meldiron self-assigned this Mar 28, 2022
@anandsubbu007
Copy link
Author

is there way to stop function if it runs in loop?

@Meldiron
Copy link
Contributor

To stop a function, make sure you don't update the document again. The best solution would be to do the check right at the top of your function - if the difference between updatedAt in the function and Date.now() is too small, return the response immediately return $response->send('Stopped to prevent infinite loop.').

@OHeroJ
Copy link

OHeroJ commented May 24, 2022

createdAt updatedAt is something that should have been available with appwrite. Otherwise, the best example is provided, instead of users constantly trying to make mistakes。

After 2 days of experience, I feel sorry for the 22k github stars, and from the user's point of view, the development is inefficient and frustrating.

@stnguyen90
Copy link
Contributor

createdAt updatedAt is something that should have been available with appwrite

@OHeroJ, thanks for your feedback. 🙏 These attributes should be available by default as of 0.15.0!

@anandsubbu007, do you have any other questions or can this issue be closed?

@stnguyen90
Copy link
Contributor

Closing due to inactivity and since we have $createdAt and $updatedAt now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants