Reputation: 921
In our app we are constantly using callable functions and sometimes the cold start can be a headache, given the fact that we are still developing it and there are no users using them other than us.
What we thought to speed up this process is to call every function (they're not much, around 20 at the moment, our bill won't go to the moon) when we open the app, before logging in, and just returning a null value without executing any other code inside it. This will hot-load them to be used in the next few minutes, avoiding cold starts and allowing us to test our front+back-end code quick and easily.
However, we have some trigger functions like adding user details after creation, that do have cold starts, but can't be called, so we can't "hot load them".
Is there any way to actually trigger these functions AND send them data through a parameter? Or this there any other approach to this situation?
Upvotes: 9
Views: 7279
Reputation: 317828
Triggers that are not based on HTTP are called "background triggers". The Firebase tools don't provide way to programmatically trigger a background function deployed to Cloud Functions without actually performing that action that would trigger it. There is no direct invocation, like there is when you're using the local emulator.
If you're willing to adopt Google Cloud tools, you can use the gcloud command line or the Google Cloud console to trigger a function directly.
Upvotes: 10
Reputation: 816
I found some documentation on direct triggers that at least matches my experience with the Google Cloud functions console, where functions can be triggered manually. There is also an interesting command line example that makes it seem possible to supply data to the functions. Note what they say about quotas and development vs. production, though I note your question was about development.
To support quick iteration and debugging, Cloud Functions provides a call command in the command-line interface and testing functionality in the GCP Console UI. This allows you to directly invoke a function to ensure it is behaving as expected. This causes the function to execute immediately, even though it may have been deployed to respond to a specific event.
Note: Direct Triggers use the Call API. This API has a limited quota which cannot be increased. It is intended for testing and debugging and should not be used in production.
...
gcloud functions call YOUR_FUNCTION_NAME --data '{"name":"Keyboard Cat"}'
Upvotes: 5