if (!snapshot.exists()) {
// function triggered by a delete
return emptyPromise();
}
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/cf5009ec-31c3-4b37-b874-e29fffbe7c6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Laurent,It seems, at first glance, that this may be overly complicated. But it's going to be hard to be very useful without a better understanding of the underlying use case instead of just the implementation details (see XY problem)Some initial ideas to reduce function invocations:
- Move the code from F2 into F1 in an if( counter == 0 ) block
- Store the counter in a separate path and monitor that in F2 so it's not retriggered on remove
- Have F1 write a "remove request" or other trigger to another path, and have F2 monitor there
☼, Kato
On Mon, May 29, 2017 at 5:10 AM, Laurent Pellegrino <laurent.p...@gmail.com> wrote:
Hello,I have a use case where the Firebase realtime database is used to perform a synchronization between multiple instances of a same cloud function F1.This function F1 initializes or decrements a counter in a specific path P/id/counter on the realtime database by using a transaction (id is shared between F1 instances).Another function F2 is configured to be triggered when a write to P/{id} is performed. The purpose of F2 is to perform an action when the counter value is equal to 0 (meaning all F1 executions for a given id have completed). Thus, F2 returns an empty promise if the counter is greater than 0. Otherwise, the action is triggered and then the database entry P/id removed, which retriggers F2. In order to avoid the circular dependency, I detect with the following piece of code if the current snapshot contains any data:if (!snapshot.exists()) {
// function triggered by a delete
return emptyPromise();
}
The flow works pretty well. However, each synchronization requires a dummy execution for F2.I wonder if there a mean to better handle such a scenario? at least having the possibility to differentiate when a function is triggered (onWrite vs {onInsert, onUpdate or onRemove}) would help to resolve this issue.Is there new database event handlers planned in the new future? or something that could help for creating rendez-vous between functions?Kind Regards,Laurent Pellegrino
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/cf5009ec-31c3-4b37-b874-e29fffbe7c6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.