Cloud Code function running twice

狂风中的少年 提交于 2019-12-24 02:17:23

问题


I have written a cloud function that is working well.

Sometimes this function is being executed more than one time for the same user (I made sure that only one request is being requested from the client android app).

After some debugging I noticed that this problem happens if the connection is bad. I may be or may not be correct.

How to overcome such an issue?


回答1:


As in the comments I also don't believe the client SDKs would duplicate a Cloud Function call on a bad connection. The expected behaviour would be for them to throw a network-related exception on the client side and not call it again. A problem would arise if the Cloud Function runs successfully and the client is only unable to get the result back.

I can think of the following solutions, with no more details about the Cloud Function itself:

  1. Try to make the function idempotent - Meaning that even if it runs twice the end result is the same, assuming the same input/parameters.

  2. Cache the results and manually throttle the function - This is more complicated, and is only needed if the network problem persists and you can't work around eliminating the side effects of the function. You would have to create another Class to cache the results of the function (maybe keyed by the parameters) and returning the same result with no computation and side effects.



来源:https://stackoverflow.com/questions/33524450/cloud-code-function-running-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!