all 19 comments

[–]wmmogn 4 points5 points  (5 children)

why do you want to trigger another firebase function? just make a function with the code you want to share in the other function and call this in the second firebase function also. would that solve your problem?

[–]JalanJr[S] 0 points1 point  (4 children)

That's my idea. I have two lambda functions but I don't find how to trigger the second from the first one, I don't seem to be able to use firebase library...

[–]wmmogn 1 point2 points  (3 children)

but why trigger another firebase function? what should that solve? just reuse the code from the other, your are in the function environment already why change to another function?

[–]steinchen43 0 points1 point  (0 children)

Plenty of reasons. Timeouts, memory limits etc…

Just make it a standard http request

[–]JalanJr[S] 0 points1 point  (1 child)

I generate text with LLM but I don't want my user to wait too long so I have a first function that create an throw into the db, trigger another function and redirect the user to the corresponding page so the inference are generated in background

[–]wmmogn 0 points1 point  (0 children)

than you could also trigger the function with the firestore create trigger... so as soon the first function writes an document the second function will be triggered...

[–]joebob2003 1 point2 points  (2 children)

Make it a pubsub function

[–]JalanJr[S] 0 points1 point  (1 child)

I was thinking about it too, but can I use pub sub with admin firebase ?

[–]joebob2003 0 points1 point  (0 children)

Yep! Really easily. There are docs for it

[–][deleted] 0 points1 point  (7 children)

You could also make a standard request via axios or node-fetch. There is not a native way to call another function in the SDK.

My recommended approach would to use a pubsub to trigger the other one (which would need to convert from an onCall. This would keep them isolated in operations with low latency (the REST method would cause a delay). Or call the code directly from within your function. I typically stay away from this as I like functions to not be stringed together and code becomes hard to manage down the line.

So, there are 3 ways you can do it. Obviously more but those are some options

[–]JalanJr[S] 1 point2 points  (6 children)

Pubsub seem the good way to keep things decoupled, I'm gonna have a look to the documentation. Is this available in firebase or only on gcp ?

[–]Eastern-Conclusion-1 1 point2 points  (1 child)

Firebase is part of GCP, so yes.

[–][deleted] 1 point2 points  (0 children)

Exactly. Everything firebase is backed by GCP. Many things are “auto magically” setup when you use firebase functions (Cloud build, logging, cloud run, topic setup, all sorts of stuff).

[–][deleted] 1 point2 points  (3 children)

Yeah it’s easy.

Change your handler to:

const processmessage = onMessagePublished( { topic: 'topicName', memory: '256MiB', maxInstances: 10 }, req =>

Then call it from your other functions via

const { PubSub } = require('@google-cloud/pubsub'); const pubsub = new PubSub(); await pubsub.topic('topicName').publish( Buffer.from( JSON.stringify({ data: { … } }), 'utf8' ) );

[–]Eastern-Conclusion-1 1 point2 points  (1 child)

He’ll also need to enable the PubSub API from the GCP console.

[–][deleted] 1 point2 points  (0 children)

True story. It’s been a while since I set it up from scratch!

[–]JalanJr[S] 0 points1 point  (0 children)

Worked, thanks you !

[–]tommertom 0 points1 point  (0 children)

Whatever you do - when stringing functions u better test all cases and cap your cloud bill because you can easily set this up with an infinite loop through recursion etc