Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure timeout of Firebase functions on local

I want to do some intense job on firebase functions and it usually takes more than 60 seconds. On production, I can set timeout longer from web console but I cannot find setting for local environment.

Following is the command which I'm using to start serving.

firebase serve --only functions

I'm using HTTPS trigger and following is the command to trigger my function on local.

functions-emulator call myfunc --data='{"uid":"user_id_1"}'

Is there way to configure timeout on local?

like image 951
kasahara Seiji Avatar asked Sep 01 '17 17:09

kasahara Seiji


People also ask

Can you run Firebase locally?

The Firebase Local Emulator Suite is a set of advanced tools for developers looking to build and test apps locally using Cloud Firestore, Realtime Database, Cloud Storage, Authentication, Cloud Functions, Pub/Sub, Firebase Hosting and Firebase Extensions.


3 Answers

You can set the timeout and memory options in local using the RunWith function

const runtimeOpts = {
 timeoutSeconds: 300,
 memory: '1GB'
}

exports.myStorageFunction = functions
.runWith(runtimeOpts)
.storage
.object()
.onFinalize((object) = > {
  // do some complicated things that take a lot of memory and time
});

The maximum value for timeoutSeconds is 540, or 9 minutes. Valid values for memory are:

128MB
256MB
512MB
1GB
2GB

like image 81
Youssef Saber Avatar answered Oct 11 '22 09:10

Youssef Saber


I struggled with this for a while, but finally found this solution:

  • In your functions directory, add a file named .env.local
  • Add this single line to that file: FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540s
  • Perform the build of your functions.
  • Shut down and then restart your local emulator. The timeout set in this new .env.local file should be honored.

h/t to volkyeth for the related GitHub firebase issue response: https://github.com/firebase/firebase-tools/issues/2837#issuecomment-1048878134

like image 39
SuttonY Avatar answered Oct 11 '22 10:10

SuttonY


There is a known issue with the Firebase emulator ignoring runWith({timeoutSeconds: }) when running Firebase functions locally.

Until Firebase fixes this, @SuttonY's answer provides one solution for changing the timeout setting locally, which is to create an .env.local file.

Another solution is to set the timeout variable in the command line when you run the Firebase emulator. For example, this is the command I use to start my emulator:

FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540 firebase emulators:start --only functions

Credit to @tiagohillebrandt for finding and posting this on the open GitHub issue. https://github.com/firebase/firebase-tools/issues/2837

like image 25
most200 Avatar answered Oct 11 '22 09:10

most200